Could somebody explain the code by Elias Wegert to me?

2 次查看(过去 30 天)
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 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by