solve IVP with ode45

20 ビュー (過去 30 日間)
Dawid Andrasik
Dawid Andrasik 2020 年 7 月 28 日
回答済み: sawera 2025 年 8 月 6 日
So I am trying to generate an ODE45 graph with the file provided. I made the modification which I believe are correct but the graph generated at the output is not correct. The second function
function dYdt=f(x,Y)
has a modified version of my function and I am wondering if that is causing the ODE function not to generate the proper input. Would anyone be able to advise on a solution or where I am going wrong ?
Thank you

採用された回答

Alan Stevens
Alan Stevens 2020 年 7 月 28 日
Looks like your equation is not correct for non-linear pendulum! Try the following:
% If u = angle from vertical then d^2u/dt^2 = -(g/l)sin(u)
%
% Let v = du/dt; dv/dt = -(g/l)sin(u);
Y0 = [1 2];
tspan = 0:0.1:10;
ge = 32; % Earth
[t, Y] = ode45(@f, tspan, Y0, [], ge);
ue = Y(:,1);
gm = 0.165*ge;
[t, Y] = ode45(@f, tspan, Y0, [], gm);
um = Y(:,1);
plot(t, ue, t, um), grid
xlabel('time'), ylabel('angle')
legend('Earth','Moon')
function dYdt = f(~,Y,g)
l = 3;
u = Y(1);
v = Y(2);
dudt = v;
dvdt = -g/l *sin(u);
dYdt = [dudt; dvdt];
end
  1 件のコメント
Dawid Andrasik
Dawid Andrasik 2020 年 7 月 28 日
thank you, this clarified the problem to me.

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

その他の回答 (1 件)

sawera
sawera 2025 年 8 月 6 日
find exact solution of IVPs, then compute using approximate solution at x=0:0.2.2:2 using ode45 command

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by