How to solve third order equation using ode45

조회 수: 20 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by