How to use ODE45 to solve a second order system of equations?

2 次查看(过去 30 天)
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?

回答(1 个)

Torsten
Torsten 2016-2-9
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.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by