MATLAB: Plot just y or y’ in a second order eq.

plotplotting

so i when i use the order of ploting it plots y, y', x and x' i just wanna it to plot just y' and x the other two remove them
format long
syms y(t) x(t)
[V] = odeToVectorField(diff(y, 2) == -1*(1-1*cos(2*t))*y);
M = matlabFunction(V,'vars', {'t','Y'});
[t,y] = ode45(@(t,Y)M(t,Y),tspan,[0 1]);
[t,x] = ode45(@(t,Y)M(t,Y),tspan,[1 0]);
hold on
plot(t,x)
plot(t,y)
hold off

Best Answer

syms y(t) x(t)
[V] = odeToVectorField(diff(y, 2) == -1*(1-1*cos(2*t))*y);
M = matlabFunction(V,'vars', {'t','Y'});
[ty,y] = ode45(@(t,Y)M(t,Y),tspan,[0 1]);
[tx,x] = ode45(@(t,Y)M(t,Y),tspan,[1 0]);
hold on
plot(tx, x(:,1));
plot(ty, y(:,2));
hold off
legend({"x", "y'"})