The Complex Numbers
The complex numbers extend the reals with one new number whose square is −1. With them every polynomial has roots, every matrix has eigenvalues, and rotations become multiplications. This appendix collects the facts the rest of the course uses.
Definition and arithmetic
A complex number is with real , where . We call the real part and the imaginary part. The set of all of them is . Arithmetic follows the usual rules of algebra, replacing by −1 whenever it appears:
| Operation | Rule |
|---|---|
| Addition | |
| Multiplication | |
| Conjugate | |
| Modulus | , and |
| Division | for |
For example, , and
which undoes the multiplication, as it should.
is a field
Addition and multiplication of complex numbers satisfy every field axiom: both are commutative and associative, multiplication distributes over addition, 0 and 1 are the identities, and every nonzero has an inverse . So everything in this course that only used field operations, Gaussian elimination, inverses, determinants, works unchanged over . One thing does not have is an ordering: there is no sensible way to say or .
Useful conjugate rules: , , , , and is real exactly when .
Complex numbers in Python
Python has complex numbers built in, written with j (the engineers' letter) instead of . NumPy handles complex arrays, and SymPy uses I for exact work.
import cmath
z, w = 2 + 3j, 1 - 1j
print("z * w =", z * w)
print("(z*w) / w =", (z * w) / w)
print("conjugate =", z.conjugate(), " |z| =", round(abs(z), 4))
print("z * conj z =", z * z.conjugate())
print("sqrt(-4) =", cmath.sqrt(-4))
print("Re, Im =", z.real, z.imag)z * w = (5+1j)
(z*w) / w = (2+3j)
conjugate = (2-3j) |z| = 3.6056
z * conj z = (13+0j)
sqrt(-4) = 2j
Re, Im = 2.0 3.0
math.sqrt(-4) raises an error; cmath.sqrt works in . SymPy gives exact results:
from sympy import I, sqrt, simplify, expand, conjugate, Abs, solve, symbols
z = 2 + 3*I
print("1/z =", simplify(1 / z))
print("(1 + I)**8 =", expand((1 + I)**8))
print("|z| =", Abs(z), " conj =", conjugate(z))
x = symbols("x")
print("roots of x**2 + 2*x + 5:", solve(x**2 + 2*x + 5, x))1/z = 2/13 - 3*I/13
(1 + I)**8 = 16
|z| = sqrt(13) conj = 2 - 3*I
roots of x**2 + 2*x + 5: [-1 - 2*I, -1 + 2*I]
Solving quadratics
With complex numbers the quadratic formula always works. For with real coefficients and negative discriminant , the roots are
a conjugate pair. In general, if a polynomial has real coefficients and is a root, then so is (conjugate both sides of ). This is why real matrices have their complex eigenvalues in conjugate pairs.
Matrices of complex numbers
Since is a field, matrices with complex entries can be added, multiplied, row-reduced and inverted as usual:
import numpy as np
A = np.array([[1, 1j], [2, 1 + 1j]])
b = np.array([1, 0])
x = np.linalg.solve(A, b)
print("det A =", np.round(np.linalg.det(A), 10))
print("x =", np.round(x, 4), " check A x =", np.round(A @ x, 10) + 0)det A = (1-1j)
x = [ 0.+1.j -1.-1.j] check A x = [1.+0.j 0.+0.j]
(.)
In software
- Signal processing and audio. FFT output is complex: the modulus is the amplitude of a frequency, the angle its phase.
- Electronics. AC circuit analysis uses complex impedances, so that capacitors and inductors become "complex resistors" in the same linear equations as resistor networks.
- Graphics. 2D rotations are multiplication by complex numbers of modulus 1 (next lesson); fractals like the Mandelbrot set iterate .
- Quantum computing. Amplitudes are complex numbers (Unitary and Hermitian Matrices).
Exercises
Exercise 1: Multiply and divide
Compute and .
Answer
and .
Solution
Exercise 2: Powers of
What is ?
Answer
−1.
Solution
Powers of repeat with period 4: . , so .
Exercise 3: Complex roots
Solve .
Answer
.
Solution
, , so . Check: , and .
Exercise 4: Inverse of a complex matrix (code)
Find the inverse of .
Answer
.
Solution
. The formula swaps the diagonal and negates the off-diagonal entries, then divides by .
from sympy import Matrix, I
A = Matrix([[1, I], [I, 2]])
print(A.det(), A.inv().tolist())3 [[2/3, -I/3], [-I/3, 1/3]]
Test yourself
What is ?
- 2
- 0
If is a root of a polynomial with real coefficients, which other number must be a root?
- None necessarily
How do you write the imaginary unit in plain Python?
- i
- 1j
- I
- sqrt(-1)