How to plot the required number of subplots?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Chunru
2022-1-21
编辑:Chunru
2022-1-21
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 个评论
Chunru
2022-1-21
Extend range of x will make multiple peaks. You may need to check the problem formulation.
更多回答(1 个)
Chunru
2022-1-21
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
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
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!