How to solve third order equation using ode45

11 ビュー (過去 30 日間)
Álvaro Recalde
Álvaro Recalde 2022 年 5 月 16 日
回答済み: Sam Chak 2022 年 5 月 16 日
Hi, I was wondering if you could help me, I'm trying to solve the following third order equation, using ode45 for the range from [0,5]. Apart from that, I'd need to plot the different solutions of y', y'' and y.
My function is this one:
y'''-y'' * y +1 = 0
y(0) =1
y'(0)=0
y''(0)=0.1
I don't know how to apply ode45 for this equation, I'd gladly accept any help.
Thank you very much.
  1 件のコメント
Torsten
Torsten 2022 年 5 月 16 日
Setting y(1) = y, y(2) = y' and y(3) = y'', your differential eqation can be written as a system of equations:
dy(1)/dt = y(2)
dy(2)/dt = y(3)
dy(3)/dt = y(3)*y(1) - 1
with initial conditions
y(1)(0) = 1
y(2)(0) = 0
y(3)(0) = 0.1
Now look at the page of ODE45 on how to set up this system:

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

採用された回答

Star Strider
Star Strider 2022 年 5 月 16 日
I let the Symbolic Math Toolbox do everything —
syms y(t) T Y
Dy = diff(y);
D2y = diff(Dy);
D3y = diff(D2y);
Eq = D3y - D2y * y + 1
Eq(t) = 
[VF,Sbs] = odeToVectorField(Eq)
VF = 
Sbs = 
yfcn = matlabFunction(VF, 'Vars',{T,Y})
yfcn = function_handle with value:
@(T,Y)[Y(2);Y(3);Y(1).*Y(3)-1.0]
ics = [0 0 0];
[t,y] = ode45(yfcn, [0 5], ics);
figure
plot(t,y)
grid
legend(string(Sbs), 'Location','best')
.

その他の回答 (1 件)

Sam Chak
Sam Chak 2022 年 5 月 16 日
@Álvaro Recalde, I'll show an example from
function dydt = odefcn(t, y)
dydt = zeros(3,1);
dydt(1) = y(2); % y' = ...
dydt(2) = y(3); % y'' = ...
dydt(3) = - 3*y(3) - 3*y(2) - y(1); % y''' = ...
end
and run ode45 to solve it
tspan = [0 10];
y0 = [1 0.5 0];
[t, y] = ode45(@odefcn, tspan, y0);

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by