Search code examples
matlabcomplex-numbers

MATLAB ploting a range of graphic for complex representation


I'm trying to plot various representations of the same function in a window in order to understand its geometry. Nevertheless, I'm bounded by my skills in matlab... My objective is to create a program that is really able to make anyone able to understand the geometry of the function, showing every angle of it.

I'm trying to have on the same window : enter image description here

  1. the representation of real and imaginary part, using the Riemann's surface.

How Can I Plot a Complex Function With Phase Information in MATLAB With Brightness

  1. The representation using brightness and colors of the same thing (not like in the link where they plot the magnitude and the phaze).

enter image description here

in this link, one great helper had good ideas, it's just I don't think the plot is smooth enough, and the colors are weird... Domain coloring (color wheel) plots of complex functions in Octave (Matlab)

  1. And then in another window the same thing but instead of ploting the real and imaginary part, to plot the magnitude and the phaze.

  2. Finally, in a last window, I would really like to plot something like what we see on wolfram alpha (that's the example for 1/z) : enter image description here

So what I've found so far :

https://www.mathworks.com/help/matlab/visualize/visualizing-four-dimensional-data.html?ue

and so in matlab I'm for now able to vizualize like on the first picture with this code :

r = (0:1:15)';                        % create a matrix of complex inputs
theta = pi*(-1:0.05:1);
z = r*exp(1i*theta);
w = log10(z)  ;                                % calculate the complex outputs



figure('Name','Graphique complexe'  , 'units','normalized','outerposition',[ 0.08 0.1 0.8 0.55]);
subplot(121)
surf(real(z),imag(z),real(w),imag(w))    % visualize the complex function using surf
xlabel('Real(z)')
ylabel('Imag(z)')
zlabel('Real(u)')
cb = colorbar;
cb.Label.String = 'Imag(v)';

subplot(122)
surf(real(z),imag(z),imag(w),real(w))    % visualize the complex function using surf
xlabel('Real(z)')
ylabel('Imag(z)')
zlabel('Imag(v)')
cb = colorbar;
cb.Label.String = 'Real(u)';

But I have one problem. Maybe I'm wrong, but when I'm ploting z^2, the imaginary is, I guess, not linear (like it would have to be : Im z^2 = -2xy ) but quadratic, just like the real part : x^2-y^2 ... Same problem when plotting the identity, the range for the angle is weird... it goes from -15 to 15...

Moreover, I would really enjoy having a range of color that is conventional, from blue to red, using this rainbow of colors :

enter image description here

and I don't know how to change the colors... I neither do know how to change the range of the scale on the right of the plot in order to make it written in terms of "pi" and not in radians... I guess it would be a lot more readable...

Alright, if you have any idea in order to do the trick, I would really enjoy to make it in practice :) I know I ask a lot of things, but even if it is only a crunch of the whole code, it will be useful, and I'll try to unify everything.

Thank you everyone !


Solution

  • Alright, it's a lot to go through so lets take the simple things first before I try to understand the rest.

    Changing color gradient: Add thus code right after declaring the

     colorbar
     colormap jet; %gradient from blue to red
    

    Changing the scales to numerals of pi: In the plot section just add the code and it should do the trick

    xticks([-pi -pi/2 0 pi/2 pi])
    xticklabels({'-\pi','-\pi/2','0','\pi/2','2\pi'})
    

    For the rest, I'll need some more time, or somebody else can try to answer.