Could somebody explain the code by Elias Wegert to me?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Guillaume
le 11 Oct 2017
Modifié(e) : Guillaume
le 11 Oct 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 commentaires
Plus de réponses (1)
Walter Roberson
le 11 Oct 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 commentaires
Voir également
Catégories
En savoir plus sur Analog Filters dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!