필터 지우기
필터 지우기

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!

조회 수: 2 (최근 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