Numerical solution for a 2nd order ode

8 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-3-31
"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.

请先登录,再进行评论。

回答(1 个)

Torsten
Torsten 2017-3-31
编辑:Torsten 2017-3-31
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by