MATLAB only plotting most recent graph
I don’t understand why matlab is only plotting figure 2
t0 = 0; tf = 50; y0 = [-0.5;0.5];
[t,Y] = ode45(@f,[t0,tf],y0,[]);
y=Y(:,1);v=Y(:,2);
[t,Y(:,1),Y(:,2)];
% y in output has 2 columns corresponding to u1 and u2
figure(1);
plot(t, y,’b-‘, t,v,’r-‘ )
xlabel(‘t’); ylabel(‘y, v = y”’);
legend(‘y(t)’,’v(t)’)
ylim([-2.5,2.5]);xticks(0:10:50);
grid on
figure(2);
plot(y,v); axis square; xlabel(‘y’); ylabel(‘v=y”’);
ylim([-2.5,2.5])
xlim([-2.5,2.5])
grid on
hold off
% plot the phase plot %———————————————————————-
function dydt = f(t,Y)
y = Y(1); v = Y(2);
dydt = [v;-2*sin(t)-v-2*y ];
endI don’t understand why matlab is only plotting figure 2
t0 = 0; tf = 50; y0 = [-0.5;0.5];
[t,Y] = ode45(@f,[t0,tf],y0,[]);
y=Y(:,1);v=Y(:,2);
[t,Y(:,1),Y(:,2)];
% y in output has 2 columns corresponding to u1 and u2
figure(1);
plot(t, y,’b-‘, t,v,’r-‘ )
xlabel(‘t’); ylabel(‘y, v = y”’);
legend(‘y(t)’,’v(t)’)
ylim([-2.5,2.5]);xticks(0:10:50);
grid on
figure(2);
plot(y,v); axis square; xlabel(‘y’); ylabel(‘v=y”’);
ylim([-2.5,2.5])
xlim([-2.5,2.5])
grid on
hold off
% plot the phase plot %———————————————————————-
function dydt = f(t,Y)
y = Y(1); v = Y(2);
dydt = [v;-2*sin(t)-v-2*y ];
end I don’t understand why matlab is only plotting figure 2
t0 = 0; tf = 50; y0 = [-0.5;0.5];
[t,Y] = ode45(@f,[t0,tf],y0,[]);
y=Y(:,1);v=Y(:,2);
[t,Y(:,1),Y(:,2)];
% y in output has 2 columns corresponding to u1 and u2
figure(1);
plot(t, y,’b-‘, t,v,’r-‘ )
xlabel(‘t’); ylabel(‘y, v = y”’);
legend(‘y(t)’,’v(t)’)
ylim([-2.5,2.5]);xticks(0:10:50);
grid on
figure(2);
plot(y,v); axis square; xlabel(‘y’); ylabel(‘v=y”’);
ylim([-2.5,2.5])
xlim([-2.5,2.5])
grid on
hold off
% plot the phase plot %———————————————————————-
function dydt = f(t,Y)
y = Y(1); v = Y(2);
dydt = [v;-2*sin(t)-v-2*y ];
end graph problem MATLAB Answers — New Questions