Hi Aisha,
Taking the second part first, a phase angle can be either positive or negative. The Matlab angle function uses the usual convention, -pi < theta <= pi. But phase angle has a 2*pi ambiguity, in that you can add 2*pi to any phase angle without changing the essential results. So if you want all positive angles, you can change the range to 0 <= theta < 2*pi, by using the mod function for example:
This process leaves the previous positive angles alone and adds 2*pi to the negative ones.
Suppose you have the function u = z in the complex plane. As you go around the origin, starting on the negative x axis, Its phase angle varies from -pi to pi. Using the parula colorbar, the plot on the upper left shows this, with a 2*pi discontinuity from yellow to purple on the negative x axis. That discontinuity is not really consequential, though, so it helps to use a colorbar that goes through the colors and ends where it began. Then the 2*pi disontinuity is not visible. The upper right plot below does that, using a colormap called wheelmap (see details there). Wheelmap is best used in conjuction with the command
so the colorbar always goes between those limits. (Otherwise autoscaling of the limits can mess things up).
The function u = sqrt(z) is also shown below. In that case, though, the discontinuity on the negative x axis is real, since the size of the discontinuity is pi and not 2*pi.
Magnitude plots are not as interesting as angle plots. The below show magnitude (actually log10 magnitude) and phase for a quadratic function and for a sine function. The roots of the quadratic are quite visible. You can do the same thing as with function 1 in the code by just plugging in your function
u = (0.5) +(0.5+0.8660i)*z +(-0.25+0.4330i)*z.^2
It turns out that the zeros of the function are at
-0.4967 + 0.8718i and -0.5033 + 0.8603i
though, so you will have to change xx and yy in the code below to create much smaller upper and lower limits and much finer spacing, in order to resolve the zeros.
surf(x,y,angle(u),'edgecolor','none')
surf(x,y,angle(u),'edgecolor','none')
surf(x,y,angle(u),'edgecolor','none')
colormap(gca,wheelmap(10))
title('u = sqrt(z), wheelmap')
u = (z-(2+2i)).*(z-(-2+i));
surf(x,y,log10(abs(u)),'edgecolor','none')
surf(x,y,angle(u),'edgecolor','none')
title('polynomial, angle')
surf(x,y,log10(abs(u)),'edgecolor','none')
surf(x,y,angle(u),'edgecolor','none')
.
function map = wheelmap(n,sat,rev)
n = 0; sat = 2/3; rev = 'x';
map = circshift(map,n,1);