Please help me, how to plot for this function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
soe min aung
le 22 Jan 2021
Modifié(e) : soe min aung
le 22 Jan 2021
k1 = 0:100;
k2 = linspace(50,150,101);
[K1,K2] = meshgrid(k1,k2);
g = (1./(1-(((50*K1)/pi)^2))).*((50./pi)^2)*1i*K1*(1-exp(-1i*100*K1))...
*(1./(1-(((100*K2)/pi)^2))).*((100./pi)^2)*1i*K2*(exp(-1i*150*K2)+exp(-1i*50*K2));
surf(K1,K2,g)
0 commentaires
Réponse acceptée
Bram Schroeders
le 22 Jan 2021
Because complex doubles contain two dimensions, it is not possible to plot a complex plane this way. You can either plot the real part, the imaginary part or the norm of the individual components in a surf-plot. You can create and plot these components like this:
k1 = 0:100;
k2 = linspace(50,150,101);
[K1,K2] = meshgrid(k1,k2);
g = (1./(1-(((50*K1)/pi)^2))).*((50./pi)^2)*1i*K1*(1-exp(-1i*100*K1))...
*(1./(1-(((100*K2)/pi)^2))).*((100./pi)^2)*1i*K2*(exp(-1i*150*K2)+exp(-1i*50*K2));
g_real = real(g);
g_imag = imag(g);
g_norm = zeros(size(g));
for i = 1:size(g,1)
for j = 1:size(g,2)
g_norm(i,j) = norm(g(i,j));
end
end
subplot(1,3,1)
surf(K1,K2,g_real)
title('real part of g');
subplot(1,3,2)
surf(K1,K2,g_imag)
title('imaginary part of g');
subplot(1,3,3)
surf(K1,K2,g_norm)
title('norm of individual components of g');
1 commentaire
Plus de réponses (1)
John D'Errico
le 22 Jan 2021
your function is complex. But a complex variable is really TWO variables, bundled into one. In ths case, it appears the imaginary part of g is virtually constant to within floating point trash.
>> min(imag(g),[],'all')
ans =
5927418.94592444
>> max(imag(g),[],'all')
ans =
5927418.94592444
>> range(imag(g),'all')
ans =
4.65661287307739e-09
But that imaginary part is non zero. So it makes no sense to try to plot a complex variable using surf.
At best, you can plot the real and imaginary parts separately. Since the imaginary part is boring...
surf(K1,K2,real(g))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/496588/image.jpeg)
Well, the real part is also pretty darn boring. Only along one edge of the surface does anything happen.
>> min(real(g),[],'all')
ans =
544051.035191288
>> max(real(g),[],'all')
ans =
544051.035191291
And what did happen was not much. Still down in the least significant bits.
Your function is essentially constant to within an ability to compute it in double precision.
Voir également
Catégories
En savoir plus sur Data Type Identification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!