How to use ODE45 to solve a second order system of equations?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to solve:
d^2t/ds^2 = 0
d^2r/ds^2 = 0
I know that this is a straight line, however I'm going to extrapolate this to another example.
So what I have is
function dy = myode(t,y)
dy = zeros(2,1);
dy(1) = y(2);
dy(2) = 0;
I can call this buy using
[T,Y] = ode45(@myode,0:5,[1;0])
Any help is appreciated!
Edit:
yin=[0 4]; % initial values
time=[0 5];
[x,y]=ode45(@myode,time,yin);
plot(x,y)
where myode is
function dy=myode2(~,y)
dy=[0;0];
dy(1)=y(2);
dy(2)= 0;
Now the problem is the plot. I get the correct straight line(blue) but what is this pesky red line at y = 4?
0 Kommentare
Antworten (1)
Torsten
am 9 Feb. 2016
It's the derivative of y (y(2)) which is identically 4.
If you only want to plot y, use
plot(x,y(:,1));
Best wishes
Torsten.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!