plotting 4 variables in the same graph
Mostra commenti meno recenti
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])
Risposte (1)
Star Strider
il 25 Lug 2020
Modificato: Star Strider
il 25 Lug 2020
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.
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!