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

2 ビュー (過去 30 日間)
Mr_Turnip_Head
Mr_Turnip_Head 2016 年 2 月 9 日
回答済み: Torsten 2016 年 2 月 9 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by