Numerical solution for a 2nd order ode
Afficher commentaires plus anciens
Hi everyone, I'm struggling to find the numerical solution for the following equation and conditions:
y'' + (0.2)*y' - y - y^3 = (0.3)*cos(wt) y(0) = 0 y'(0) = 0
I need to plot a numerical solution from ti = 0 to tf = 100 for w = 0.8:0.1:1.5. I am really new to matlab so fair warning, here's what I've got so far:
syms y t;
a = y;
b = Dy;
Db = (0.3)*cos(w*t)-(0.2)*b + a - a^3;
figure;
hold on
for x = 0.8:0.1:1.5
ezplot(subs(Db, 'w', x), [0 100])
end
hold off
axis ([0 100 0 3])
title 'Numerical solutions of D2y + (0.2).*Dy - y - y.^3 = (0.3).*cos(w.*t) when w = 0.8, 0.9,..., 1.4, 1.5'
legend('w = 0.8', 'w = 0.9', 'w = 1.0', 'w = 1.1', 'w = 1.2', 'w = 1.3', 'w = 1.4', 'w = 1.5')
I'd appreciate any guidance or feedback, thank you!
1 commentaire
Jan
le 31 Mar 2017
"Numerical" solution means, that you do not use "syms".
Start with converting the 2nd order equation to a system of equations of the 1st order.
Réponses (1)
Rewrite your ODE as
y1'=y2
y2'=-0.2*y2+y1+y1^3+0.3*cos(w*t)
and use ODE45 to solve.
Look at the examples provided under
https://de.mathworks.com/help/matlab/ref/ode45.html
Best wishes
Torsten.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!