Greetings dear friends, I am trying to change some variables in the indicated code to get the waves that can be seen in the 3D graph, thanks for your help!

1 次查看(过去 30 天)
By this means the experts helped me with this code for which I am grateful and I have tried to obtain the waves indicated in the final 3D graph that I wish to create:
In the results I see this graph (Which cordially helped me by this means):
The code is this:
Thank you so much!

采纳的回答

Simon Chan
Simon Chan 2022-3-8
Better to check the limits to generate your sample figure. Looks like from -3pi to 3pi as shown below:
As the limits goes to infinity, it smears out the oscillation and becomes a straight line. So your code is correct.
clear; clc;
t = linspace(0.001,2,50);
x = linspace(-2,2,50);
[T,X] = meshgrid(t,x);
tiledlayout(3,3,'TileSpacing','compact','Padding','compact');
for k = 1:9
for r = 1:numel(x)
for s = 1:numel(t)
f = @(p) (1/(pi*sqrt(2*pi))).*(sin(p)./p).*exp(-(T(r,s)*p.^2)+i*(p*X(r,s)));
F(r,s) = integral(f,-k*pi,k*pi);
end
end
nexttile
surf(T,X,real(F));
colormap(flip(autumn()));
xlabel('t');
ylabel('x');
zlabel('u(x,t)');
title(sprintf('Limits: -%d%s to %d%s',k,'\pi',k,'\pi'));
end
for r = 1:numel(x)
for s = 1:numel(t)
f = @(p) (1/(pi*sqrt(2*pi))).*(sin(p)./p).*exp(-(T(r,s)*p.^2)+i*(p*X(r,s)));
F(r,s) = integral(f,-3*pi,3*pi);
end
end
figure(2)
surf(T,X,real(F));
colormap(flip(autumn()));
xlabel('t');
ylabel('x');
zlabel('u(x,t)');
  3 个评论
Simon Chan
Simon Chan 2022-3-8
Try to clear the workspace or restart MATLAB before running the code.
clear; clc; % <--- Clear the workspace
t = linspace(0.001,2,50);
x = linspace(-2,2,50);
[T,X] = meshgrid(t,x);
for r = 1:numel(x);
for s = 1:numel(t);
f = @(p)(1/(pi*sqrt(2*pi))).*(sin(p)./p).*exp(-(T(r,s)*p.^2)+i*(p*X(r,s)));
F(r,s) = integral(f,-3*pi,3*pi);
end
end
surf(T,X,real(F));
colormap(flip(autumn()));
xlabel('t');
ylabel('x');
zlabel('u(x,t)');
Lewis HC
Lewis HC 2022-3-8
I have to tell you that you are one of the best dear friend, thank you very much, you helped me as you can not imagine, greetings!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by