Please help me, how to plot for this function?

1 visualización (últimos 30 días)
soe min aung
soe min aung el 22 de En. de 2021
Editada: soe min aung el 22 de En. de 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)

Respuesta aceptada

Bram Schroeders
Bram Schroeders el 22 de En. de 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');

Más respuestas (1)

John D'Errico
John D'Errico el 22 de En. de 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))
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.

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by