Could somebody explain the code by Elias Wegert to me?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sp00n
am 11 Okt. 2017
Bearbeitet: Guillaume
am 11 Okt. 2017
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.
0 Kommentare
Akzeptierte Antwort
Guillaume
am 11 Okt. 2017
Bearbeitet: Guillaume
am 11 Okt. 2017
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));
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 11 Okt. 2017
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!