Python - Complex Numbers

Card Puncher Data Processing

About

complex numbers in Python

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

Snippet

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

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.

Complex Plane

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

Python Plot Complex

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

Complex Number Distance

>>> abs(1+2j)
2.23606797749979

Translation

  • 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

Complex Number Translation

Translation in general:

f (z) = z + z0

where:

Arrow

  • Complex Number as an arrow

Complex Number As 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

Complex Number Arrow Composition

Multiplication

Scaling

Multiplying complex numbers by a positive real number

Complex Number Scaling Mutliplication

Reflection

Complex Number Multiplication Negative Number Reflection

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})

Rotation

Rotating a complex number z means increasing its argument.

Complex Number 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

Complex Number Theta Pi

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)])







Share this page:
Follow us:
Task Runner