How to solve third order equation using ode45
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Álvaro Recalde
le 16 Mai 2022
Réponse apportée : Sam Chak
le 16 Mai 2022
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 commentaire
Torsten
le 16 Mai 2022
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:
Réponse acceptée
Star Strider
le 16 Mai 2022
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 commentaires
Plus de réponses (1)
Sam Chak
le 16 Mai 2022
@Á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 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


