Please help me, how to plot for this function?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Bram Schroeders
2021년 1월 22일
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개)
John D'Errico
2021년 1월 22일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!