Solving 2nd order differential equation using ode45

1 回表示 (過去 30 日間)
Brendan Görres
Brendan Görres 2019 年 1 月 5 日
コメント済み: Torsten 2019 年 1 月 7 日
I am trying to solve this equation
x=0.5*x''*t^2;
Initial guess
x(0)=0;%starting point
x''(0)=0;%starting acceleration
So the place my vehicle is, depends on the acceleration an the time. I want to solve this equation with ode45 so that I get the place and acc during all given times.
This is my code:
[t,x]=ode45(@fun,[0 30],[0 0])
function dX=fun(t,X)
dX(1)=X(2);
dX(2)=2*X(1)/t^2;
dX=[dX(1);dX(2)];
end
Problem is that Matlab returns only returns NaN values. Could someone please explain why?
Thanks
  1 件のコメント
Torsten
Torsten 2019 年 1 月 7 日
You can't prescribe x''(0) for a second-order ODE. Only x(0) and x'(0) are allowed.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 5 日
Reason: Because there is division by 0 therefore nans are encountered.
[t,x]=ode45(@fun,[0.00001 30],[0.00001 0.00001])
function dX=fun(t,X)
dX(1)=X(2);
dX(2)=2*X(1)/t^2;
dX=[dX(1);dX(2)];
end

その他の回答 (0 件)

カテゴリ

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