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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lewis HC
am 7 Mär. 2022
Kommentiert: Lewis HC
am 8 Mär. 2022
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!
0 Kommentare
Akzeptierte Antwort
Simon Chan
am 8 Mär. 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 Kommentare
Simon Chan
am 8 Mär. 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)');
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!