Could somebody explain the code by Elias Wegert to me?

조회 수: 4 (최근 30일)
Sp00n
Sp00n 2017년 10월 11일
편집: Guillaume 2017년 10월 11일
I read some of the book "Visual Complex Functions" by Elias Wegert. In the epilogue, he provides a short Matlab code for plotting phase portraits:
xmin=-0.5; xmax=0.5; ymin=-0.5; ymax=0.5;
xres = 800; yres = 800;
x = linspace(xmin,xmax,xres);
y = linspace(ymin,ymax,yres);
[x,y] = meshgrid(x,y); z = x+1i*y;
f = exp(1./z);
p = surf(real(z), imag(z),0*f, angle(-f));
set(p,'EdgeColor','none');
caxis([-pi,pi]), colormap hsv(600)
view(0,90), axis equal, axis off
Since I'm very new to Matlab, I don't really get everything about it. Especially since there's an error on line 7 for me ("X, Y, Z, and C cannot be complex."). Could somebody explain to me why there's 0*f and angle(-f)? And what can I do to make it work? Thank you in advance.

채택된 답변

Guillaume
Guillaume 2017년 10월 11일
편집: Guillaume 2017년 10월 11일
The error message occurs because some elements of f are Inf + 1i*Inf, which when multiplied by 0 give 0 + 1i*NaN (I would have expected it to give NaN + 1i*NaN)
I assume that the 0*f is just a lazy way to create a zero matrix the same size as f, so you could replace that by zeros(size(f))
p = surf(real(z), imag(z), zeros(size(f)), angle(-f));

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 11일
p = surf(real(z), imag(z),zeros(size(f)), angle(-f), 'edgecolor','none');
The reason that 0*f is complex is there are two locations in f that are complex infinities, and infinity * 0 is nan

카테고리

Help CenterFile Exchange에서 Analog Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by