How to solve third order equation using ode45
조회 수: 20 (최근 30일)
이전 댓글 표시
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
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
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
[VF,Sbs] = odeToVectorField(Eq)
yfcn = matlabFunction(VF, 'Vars',{T,Y})
ics = [0 0 0];
[t,y] = ode45(yfcn, [0 5], ics);
figure
plot(t,y)
grid
legend(string(Sbs), 'Location','best')
.
댓글 수: 0
추가 답변 (1개)
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);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!