How to plot the required number of subplots?

7 visualizaciones (últimos 30 días)
Andi
Andi el 21 de En. de 2022
Comentada: Andi el 21 de En. de 2022
As per my script there should be 40 subplots. but I unable tyo recognize the subplots after 28.
Script as as follows:
clc
xs=8;
v=3;
L=20;
ta=0.2;
t=1;
n=1:1:40;
x=0:0.1:20;
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
for i=1:length(x)
u(i)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x(i)/L)*cos(omga(j)*t);
end
position = position + 1;
if position > 40; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(10,4,position);
plot(x,u)
axis off
%plot(x, u)
end

Respuesta aceptada

Chunru
Chunru el 21 de En. de 2022
Editada: Chunru el 21 de En. de 2022
xs=8;
v=1;
L=20;
ta=0.2;
t=1;
n=1:1:40;
%x=0:0.1:20;
x=0:0.1:60;
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
u = zeros(size(x));
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
u = u + sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x/L)*cos(omga(j)*t);
end
plot(x, u)
  3 comentarios
Chunru
Chunru el 21 de En. de 2022
Extend range of x will make multiple peaks. You may need to check the problem formulation.
Andi
Andi el 21 de En. de 2022
But as per formulation, the force is exerted at x=8 so, the peak shoudl be at both ends.

Iniciar sesión para comentar.

Más respuestas (1)

Chunru
Chunru el 21 de En. de 2022
Since you have applied an amplitude factor of something like exp(-n.^2). The amplitude quickly drop to zero at larger iteration.
xs=8;
v=3;
L=20;
ta=0.2;
t=1;
n=1:1:40;
x=0:0.1:20;
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
fprintf('%3d %20.7g\n', j, F(j));
for i=1:length(x)
u(i)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x(i)/L)*cos(omga(j)*t);
end
position = position + 1;
if position > 40; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(10,4,position);
plot(x,u)
axis off
%plot(x, u)
end
1 0.4113691 2 0.02863695 3 0.0003373534 4 6.725225e-07 5 2.268777e-10 6 1.29521e-14 7 1.251273e-19 8 2.04563e-25 9 5.659338e-32 10 2.649521e-39 11 2.099097e-47 12 2.81424e-56 13 6.384883e-66 14 2.451366e-76 15 1.592673e-87 16 1.751091e-99 17 3.258021e-112 18 1.025799e-125 19 5.465557e-140 20 4.927989e-155 21 7.519143e-171 22 1.941469e-187 23 8.483122e-205 24 6.272554e-223 25 7.848677e-242 26 1.661927e-261 27 5.955121e-282 28 3.611043e-303 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0
You can use a smaller value or ta or v in order to see more nonzero plot.
v=0.3;
figure;
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
fprintf('%3d %20.7g\n', j, F(j));
for i=1:length(x)
u(i)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x(i)/L)*cos(omga(j)*t);
end
position = position + 1;
if position > 40; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(10,4,position);
plot(x,u)
axis off
%plot(x, u)
end
1 0.9911567 2 0.9650932 3 0.9231682 4 0.8675151 5 0.8008624 6 0.7263123 7 0.6471032 8 0.5663805 9 0.4869985 10 0.4113691 11 0.341366 12 0.2782874 13 0.22287 14 0.1753453 15 0.1355256 16 0.1029042 17 0.07675904 18 0.05624846 19 0.04049266 20 0.02863695 21 0.01989581 22 0.01357942 23 0.009105118 24 0.005997558 25 0.003881039 26 0.00246721 27 0.001540809 28 0.0009453145 29 0.0005697553 30 0.0003373534 31 0.0001962304 32 0.0001121327 33 6.294814e-05 34 3.471508e-05 35 1.88078e-05 36 1.001019e-05 37 5.233975e-06 38 2.688471e-06 39 1.356637e-06 40 6.725225e-07
  3 comentarios
Chunru
Chunru el 21 de En. de 2022
Not sure your question. Can you clarify more?
Andi
Andi el 21 de En. de 2022
I want to make a stacked plot by summing all the plots.
u(1)=....
u(2)=...
.
U(40)=...
U(sum)=.... (sum all teh values on index basis)
and then plot (x, u)

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by