function not plotting, but no error message
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jon
am 27 Sep. 2023
Kommentiert: Dyuman Joshi
am 27 Sep. 2023
I created this function and plot but it is not plotting and I am not getting any error message.
%x1'=-3x1-200x2
%x2'=200x1-3x2
opts = odeset('RelTol',1e-6,'AbsTol',1e-8);function [dXdt] = Problem02ODEFunction(t,X)
soln = ode45(@Problem02ODEFunction,[0 1],[-10 10],opts);
figure;
plot(soln.x,soln.y(1,:),'-','linewidth',0.5);
hold on;
plot(soln.x,soln.y(2,:),'-','linewidth',0.5);
grid on;
title('Problem 2 ODE45 Solution');
xlabel('Time (s)');
ylabel('Solution');
legend('x_{1}(t)','x_{2}(t)','location','best');
function [dXdt] = Problem02ODEFunction(t,X)
x1 = X(1);
x2 = X(2);
dx1dt = -3*x1 - 200*x2;
dx2dt = 200*x1 - 3*x2;
[dXdt] = [dx1dt; dx2dt];
end
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 27 Sep. 2023
The code after the semi-colon in this line of code seems to be a typo
opts = odeset('RelTol',1e-6,'AbsTol',1e-8);function [dXdt] = Problem02ODEFunction(t,X)
After removing it, the code works and the plots are there -
%x1'=-3x1-200x2
%x2'=200x1-3x2
opts = odeset('RelTol',1e-6,'AbsTol',1e-8);
soln = ode45(@Problem02ODEFunction,[0 1],[-10 10],opts)
figure;
plot(soln.x,soln.y(1,:),'-','linewidth',0.5);
hold on;
plot(soln.x,soln.y(2,:),'-','linewidth',0.5);
grid on;
title('Problem 2 ODE45 Solution');
xlabel('Time (s)');
ylabel('Solution');
legend('x_{1}(t)','x_{2}(t)','location','best');
function dXdt = Problem02ODEFunction(t,X)
x1 = X(1);
x2 = X(2);
dx1dt = -3*x1 - 200*x2;
dx2dt = 200*x1 - 3*x2;
[dXdt] = [dx1dt; dx2dt];
end
2 Kommentare
Dyuman Joshi
am 27 Sep. 2023
No, you don't have to remove the semi colon, you have remove the part after the semi-colon.
I'll take a look at the file and get back at you.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!