MATLAB Answers

How can I plot this second-order differential equation

1 view (last 30 days)
Hyun Suk Song
Hyun Suk Song on 27 Oct 2020
Answered: Alan Stevens on 27 Oct 2020
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?

  0 Comments

Sign in to comment.

Answers (1)

Alan Stevens
Alan Stevens on 27 Oct 2020
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

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!