Python - Complex Numbers


complex numbers in Python

Python uses 'j' for the imaginary unit, not 'i'.


  • Type Complex
>>> 1j
>>> type(1j)
<class 'complex'>
  • Addition
>>> (3 + 1j) + (2 + 2j)
>>> x = 1+3j
>>> x + 1

Complex Plane

The real and imaginary parts of a complex number can be interpreted as x and y coordinates in the complex plane forming a point.

  • Coordinates
>>> x = 1+3j
>>> x.real # real number coordinates
>>> x.imag # imaginary number coordinates
  • Plot
import matplotlib.pyplot as plt
X = [x.real for x in L]
Y = [x.imag for x in L]
plt.scatter(X,Y, color='red')

  • Absolute value of z = distance from the origin to the point z in the complex plane. (In Mathematics - Mathese, |z|)

>>> abs(1+2j)


  • Geometric interpretation of f (z) = z + (1+2i)?
  • Increase each real coordinate by 1 and increases each imaginary coordinate by 2.
  • A translation can “move” the picture anywhere in the complex plane

Translation in general:

f (z) = z + z0



  • Complex Number as an arrow

Composition (Addition)

They correspond to translations f1(z) = z + z1 and f2(z) = z + z2. Functional composition: (f1 circ f2)(z) = 2z + z1 + z2



Multiplying complex numbers by a positive real number


plot({-1*z for z in L})

By i: rotation by 90 degrees

x+yi right −y + x{i}

i(x + y{i}) = x{i} + y{i^2} = x{i} − y

f(z) = i{z}

plot({1j*z for z in L})


Rotating a complex number z means increasing its argument.

Argument of z is the angle in radians between z arrow and the x axis (1 + 0i arrow).

Euler’s formula: For any real number theta, e^{theta{i}} is the point z on the unit circle with argument theta.

e = 2.718281828…

When theta = pi, z = -1

Every complex number can be written in the form z = r*e^{theta{i}} where:

  • r is the absolute value of z
  • theta is the argument of z

To augment the argument of z, we use exponentiation law <math>e^a * e^b = e^{a+b}</math>

  • r.e^{theta{i}} * e^{tau{i}} = r.e^(theta+tau){i}
  • f(z) = z . e^{tau{i}} does a rotation by angle tau
  • Rotation of 45 degrees
from math import e, pi
plot({e**(45j)*z for z in L})
  • Circle with a rayon of 2
r = 2
circle = 2*pi
plot([r*e**(t*circle/20*1j) for t in range(20)])

Powered by ComboStrap