plotting 4 variables in the same graph

i need to plot this function with 4 variables t,s,a,b
format long
p=pi ;
a=0 ;
b=0 ;
syms y(t)
for a=0:10 ;
for b=0:10;
[V] = odeToVectorField(diff(y, 2) == -1*(a-b*cos(2*t))*y);
M = matlabFunction(V,'vars', {'t','Y'});
sol = ode45(M,[0 2*pi],[0 1]);
end
end
sol.y
fplot(@(x)deval(sol,x,1),[0, 20])

답변 (1개)

Star Strider
Star Strider 2020년 7월 25일
편집: Star Strider 2020년 7월 25일

0 개 추천

I have no idea what ‘s’ is, since it only appears in your question, not in your code.
Try this:
syms y(t) t Y a b
[V,Subs] = odeToVectorField(diff(y, 2) == -1*(a-b*cos(2*t))*y);
M = matlabFunction(V,'Vars',{t,Y,a, b});
tspan = linspace(0, 2*pi, 75);
av = 0:10;
bv = 0:10;
for k1 = 1:numel(av)
for k2 = 1:numel(bv)
[t,y] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[0 1]);
yc{k1,k2} = y;
end
end
figure
hold on
for k1 = 1:11
for k2 = 1:11
plot(t,yc{k1,k2})
end
end
hold off
grid
I leave identifying the various curves to you. (There would be 121 different plots. Consider 11 different figures, with the 11 sets of curves either plotted on the same axes or with 11 subplots. The choice is yours.)
EDIT — (25 Jul 2020 at 23:56)
Corrected typographical error.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

질문:

2020년 7월 25일

편집:

2020년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by