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 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

Simon Chan
Simon Chan il 8 Mar 2022
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 Commenti
Simon Chan
Simon Chan il 8 Mar 2022
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 il 8 Mar 2022
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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by