something is wrong in my plotting code

1 visualización (últimos 30 días)
Saladin Hossam
Saladin Hossam el 4 de Ag. de 2020
Comentada: Walter Roberson el 4 de Ag. de 2020
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 comentario
Saladin Hossam
Saladin Hossam el 4 de Ag. de 2020
they till me that order is incorrect
plot(t, xc{k1,k2,:}(:,1));

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Ag. de 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 comentarios
Saladin Hossam
Saladin Hossam el 4 de Ag. de 2020
thx for help but i done some small changes to make it work but after that the colors as u see too much colors i hope that its became just 2 color one for x and one for y
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(nav, 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 = 1:11
for k2 = 1:6
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
Walter Roberson
Walter Roberson el 4 de Ag. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by