I am trying to make conformal plots of complex functions using Python, yet I keep getting plots for the inverse function.

506 Views Asked by At

I am trying to make a conformal plot of complex functions using contours in python using Matplotlib and NumPy. The thing is, whenever I run the code I get a plot for the inverse function.

For example, say I want to plot $f(z) = z^{2}$ : I would use this code:

import numpy as np

def f(z):
    return z**2  #definig function as x^2

x = np.linspace(-4,4,100) #real part of input
y = np.linspace(-4,4,100) #imaginary part of input

X,Y = np.meshgrid(x,y)

w = f(X + 1j*Y) #Plugging the real and imaginary parts into the function

plt.contour(X,Y, np.real(w)) #plots contour with the real part of the output
plt.contour(X,Y, np.imag(w)) #plots contour with the real part of the output

plt.show()

This gives me this picture:

The problem is that is the plot of the inverse function $f^{-1}(z) = \sqrt{z}$.

The picture I should have gotten should look like this:

I got that picture by changing $f(z)$ from $z^2$ to $\sqrt{z}$. I have had this problem with every function I have tried including $sin(z), \ exp(z), \ x^3$ and various other polynomials. Aside from this, I have genuinely no idea what to do or where to go from here. nor do I know what the problem actually is.

Note: I have not take complex analysis before so I dont have much knowledge about the subject so sorry if I misuse any terminology. The main reason I am doing any of this is because I think the plots look pretty. My main reference for how the plots should look is this geogebra project I made a while ago: https://www.geogebra.org/m/phmtsgrf

2

There are 2 best solutions below

1
On

Why do you think the first plot is plot for the inverse function? It looks like the correct plot for $f(z)$ to me.

For example, $Re f(z) = Re (x+iy)^2 = x^2 - y^2$ so the contours should be curves of the form $x^2 - y^2 = c$. That's exactly what the first plot looks like to me.

2
On

On your GeoGebra plot, the red and blue lines are the images of the grid (lines parallel to the axes) under the mapping.

Here, your contours are contours of constant value. That is why there is a difference in the resulting plots.