How can I plot this second-order differential equation

1 次查看(过去 30 天)
here is my start
for t1 = 0:100
for omega = 0.8:0.1:1.5
rhs = @(t,y) [y(2); -0.2.*y(2) + y - y.^3 + 0.3*cos(omega.*t)];
[t1, omega] = ode45(rhs, [0 6], omega);
plot (t1, omega);
end
end
could you help me?

回答(1 个)

Alan Stevens
Alan Stevens 2020-10-27
More like this perhaps
omega = 0.8:0.1:1.5;
n = numel(omega);
for i = 1:n
dydt = @(t,y) [y(2); -0.2*y(2) + y(1) - y(1).^3 + 0.3*cos(omega(i)*t)];
tspan = [0 100];
IC = [0 0];
[t, Y] = ode45(dydt,tspan,IC);
y = Y(:,1);
figure
plot(t,y),grid
xlabel('t'),ylabel('y')
title(['\omega = ',num2str(omega(i))])
end

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by