something is wrong in my plotting code
Afficher commentaires plus anciens
i dont know what is wrong with that code first
second i want all x in one color and all y' in onther color
thx for helping me alot
syms y(t) t Y a b x(t)
[V,Subs] = odeToVectorField(diff(y, 2) == -1*(a-b*cos(2*t))*y);
M = matlabFunction(V,'Vars',{t,Y,a, b});
tspan = linspace(0, pi, 75);
av = 0:10;
bv = 0:5;
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]);
[t,x] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[1 0]);
yc{k1,k2,:} = y;
xc{k1,k2,:} = x;
end
end
figure
hold on
for k1 = 1:101
for k2 = 1:51
hold on
plot(t, xc{k1,k2,:}(:,1));
plot(t, yc{k1,k2,:}(:,2));
hold off
end
end
hold off
grid
1 commentaire
Saladin Hossam
le 4 Août 2020
Réponses (1)
Walter Roberson
le 4 Août 2020
syms y(t) t Y a b x(t)
[V,Subs] = odeToVectorField(diff(y, 2) == -1*(a-b*cos(2*t))*y);
M = matlabFunction(V,'Vars',{t,Y,a, b});
tspan = linspace(0, pi, 75);
av = 0:10;
bv = 0:5;
nav = numel(av);
nbv = numel(bv);
yc = cell(nav, nbv);
xc = cell(nava, nbv);
for k1 = 1:nav
for k2 = 1:nbv
[t,y] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[0 1]);
[t,x] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[1 0]);
yc{k1,k2} = y;
xc{k1,k2} = x;
end
end
figure
hold on
for k1 = nav
for k2 = nbv
hold on
plot(t, xc{k1,k2}(:,1), 'displayname', sprintf('x{%d,%d}', k1, k2));
plot(t, yc{k1,k2}(:,2), 'displayname', sprintf('y{%d,%d}', k1, k2));
hold off
end
end
hold off
grid
legend show
2 commentaires
Saladin Hossam
le 4 Août 2020
Walter Roberson
le 4 Août 2020
syms y(t) t Y a b x(t)
[V,Subs] = odeToVectorField(diff(y, 2) == -1*(a-b*cos(2*t))*y);
M = matlabFunction(V,'Vars',{t,Y,a, b});
tspan = linspace(0, pi, 75);
av = 0:10;
bv = 0:5;
nav = numel(av);
nbv = numel(bv);
yc = cell(nav, nbv);
xc = cell(nava, nbv);
for k1 = 1:nav
for k2 = 1:nbv
[t,y] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[0 1]);
[t,x] = ode45(@(t,Y)M(t,Y,av(k1),bv(k2)),tspan,[1 0]);
yc{k1,k2} = y;
xc{k1,k2} = x;
end
end
figure
hold on
xcolor = 'k';
ycolor = 'b';
for k1 = 1 : nav
for k2 = 1 : nbv
hold on
plot(t, xc{k1,k2}(:,1), xcolor, 'displayname', sprintf('x{%d,%d}', k1, k2));
plot(t, yc{k1,k2}(:,2), ycolor, 'displayname', sprintf('y{%d,%d}', k1, k2));
hold off
end
end
hold off
grid
legend show
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!