TExcelTAD
Home › Calculus Essentials › Complex Numbers

Complex Numbers

Complex numbers extend the real numbers with a square root of −1. They started as a trick for solving equations like x2+1=0x^2 + 1 = 0, but they turned out to be the natural language for rotations, waves and signals. Python supports them out of the box.

The imaginary unit

Define ii as a number with

i2=−1i^2 = -1

A complex number is z=a+biz = a + bi, where a=Re⁡(z)a = \operatorname{Re}(z) is the real part and b=Im⁡(z)b = \operatorname{Im}(z) the imaginary part, both real. Real numbers are the complex numbers with b=0b = 0.

The powers of ii repeat in a cycle of four: i1=ii^1 = i, i2=−1i^2 = -1, i3=−ii^3 = -i, i4=1i^4 = 1, i5=ii^5 = i, …

Python writes the imaginary unit as j (the engineering convention), SymPy as I:

python · try it yourself
z = 3 + 4j
w = 1 - 2j

print("z + w =", z + w)
print("z * w =", z * w)
print("z / w =", z / w)
print("Re, Im of z:", z.real, z.imag)
print("conjugate of z:", z.conjugate())
print("|z| =", abs(z))
print("1j**2 =", 1j**2)
z + w = (4+2j)
z * w = (11-2j)
z / w = (-1+2j)
Re, Im of z: 3.0 4.0
conjugate of z: (3-4j)
|z| = 5.0
1j**2 = (-1+0j)

Arithmetic

Operation Rule
add (a+bi)+(c+di)=(a+c)+(b+d)i(a + bi) + (c + di) = (a + c) + (b + d)i
multiply (a+bi)(c+di)=(ac−bd)+(ad+bc)i(a + bi)(c + di) = (ac - bd) + (ad + bc)i (expand, then use i2=−1i^2 = -1)
conjugate zˉ=a−bi\bar{z} = a - bi
modulus ∣z∣=a2+b2\lvert z \rvert = \sqrt{a^2 + b^2}, and z⋅zˉ=∣z∣2z \cdot \bar{z} = \lvert z \rvert^2
divide multiply top and bottom by the conjugate of the bottom

Division by hand, (3+4i)/(1−2i)(3 + 4i)/(1 - 2i):

(3+4i)(1+2i)(1−2i)(1+2i)=3+6i+4i+8i21+4=−5+10i5=−1+2i\frac{(3 + 4i)(1 + 2i)}{(1 - 2i)(1 + 2i)} = \frac{3 + 6i + 4i + 8i^2}{1 + 4} = \frac{-5 + 10i}{5} = -1 + 2i

The complex plane and polar form

Draw a+bia + bi as the point (a,b)(a, b). Then ∣z∣\lvert z \rvert is the distance from the origin and the angle θ\theta from the positive real axis is the argument, arg⁡z\arg z. Every non-zero complex number can be written in polar form:

z=r(cos⁡θ+isin⁡θ),r=∣z∣,θ=atan2⁡(b,a)z = r(\cos\theta + i\sin\theta), \qquad r = \lvert z \rvert, \quad \theta = \operatorname{atan2}(b, a)

Euler's formula connects this to the exponential function:

eiθ=cos⁡θ+isin⁡θsoz=reiθe^{i\theta} = \cos\theta + i\sin\theta \qquad\text{so}\qquad z = r e^{i\theta}

and with θ=π\theta = \pi it gives the famous eiπ+1=0e^{i\pi} + 1 = 0. You will see why Euler's formula holds when you meet Taylor series.

Polar form makes multiplication easy:

r1eiθ1⋅r2eiθ2=(r1r2)ei(θ1+θ2)multiply lengths, add anglesr_1 e^{i\theta_1} \cdot r_2 e^{i\theta_2} = (r_1 r_2) e^{i(\theta_1 + \theta_2)} \qquad \text{multiply lengths, add angles}

Multiplying by eiθe^{i\theta} rotates a point by θ\theta around the origin. Multiplying by ii (which is eiπ/2e^{i\pi/2}) rotates by 90°.

python · try it yourself
import cmath, math

z = 1 + 1j
r, theta = cmath.polar(z)
print(f"|z| = {r:.4f}, arg z = {theta:.4f} rad = {math.degrees(theta):.1f}°")
print("back from polar:", cmath.rect(r, theta))

print("e^(iπ) + 1 =", cmath.exp(1j * math.pi) + 1)

p = 2 + 0j                                 # the point (2, 0)
for deg in [90, 180, 270, 45]:
    q = p * cmath.exp(1j * math.radians(deg))
    print(f"rotate (2, 0) by {deg:3}°: ({q.real:+.4f}, {q.imag:+.4f})")
|z| = 1.4142, arg z = 0.7854 rad = 45.0°
back from polar: (1.0000000000000002+1j)
e^(iπ) + 1 = 1.2246467991473532e-16j
rotate (2, 0) by  90°: (+0.0000, +2.0000)
rotate (2, 0) by 180°: (-2.0000, +0.0000)
rotate (2, 0) by 270°: (-0.0000, -2.0000)
rotate (2, 0) by  45°: (+1.4142, +1.4142)

The tiny leftovers such as 1.2246…e-16j are floating-point rounding: mathematically eiπ+1e^{i\pi} + 1 is exactly 0.

Roots of polynomials

The fundamental theorem of algebra says that every polynomial of degree n≥1n \ge 1 has exactly nn complex roots, counted with multiplicity. Complex numbers are what make root-finding complete. For real coefficients, non-real roots come in conjugate pairs.

The nn-th roots of unity, the solutions of zn=1z^n = 1, are e2πik/ne^{2\pi i k/n} for k=0,…,n−1k = 0, \ldots, n - 1: nn points evenly spaced on the unit circle.

python · try it yourself
import sympy as sp
import numpy as np

z = sp.symbols('z')
print(sp.solve(z**2 + 4*z + 13, z))
print(sp.solve(z**4 - 1, z))

n = 6
roots = np.exp(2j * np.pi * np.arange(n) / n)
print(np.round(roots, 4))
print("all satisfy z^6 = 1:", np.allclose(roots**6, 1))
[-2 - 3*I, -2 + 3*I]
[-1, 1, -I, I]
[ 1. +0.j     0.5+0.866j -0.5+0.866j -1. +0.j    -0.5-0.866j  0.5-0.866j]
all satisfy z^6 = 1: True

In software

  • 2D rotation: a rotation by θ\theta is multiplication by cos⁡θ+isin⁡θ\cos\theta + i\sin\theta. Quaternions extend the same idea to 3D rotation in game engines (Quaternions).
  • The FFT splits a signal into frequencies by multiplying it with the roots of unity e−2πik/ne^{-2\pi i k/n}. It powers audio equalisers, MP3 and JPEG compression, and fast polynomial multiplication (SciPy FFT).
  • Electrical engineering uses complex numbers (as j) for AC circuits, where phase matters.
  • Fractals: the Mandelbrot set is the set of cc for which z→z2+cz \to z^2 + c stays bounded.
  • Rotary position embeddings (RoPE) in many LLMs rotate pairs of embedding dimensions by position-dependent angles, which is multiplication by eiθe^{i\theta}.

Exercises

Exercise 1: Arithmetic by hand

With u=2+3iu = 2 + 3i and v=4−iv = 4 - i, compute u+vu + v, u⋅vu \cdot v and ∣v∣\lvert v \rvert.

Answer

u+v=6+2iu + v = 6 + 2i, u⋅v=11+10iu \cdot v = 11 + 10i, ∣v∣=17≈4.123\lvert v \rvert = \sqrt{17} \approx 4.123.

Solution
u+v=(2+4)+(3−1)i=6+2iu⋅v=8−2i+12i−3i2=8+10i+3=11+10i∣v∣=16+1=17\begin{aligned} u + v &= (2 + 4) + (3 - 1)i = 6 + 2i \\ u \cdot v &= 8 - 2i + 12i - 3i^2 = 8 + 10i + 3 = 11 + 10i \\ \lvert v \rvert &= \sqrt{16 + 1} = \sqrt{17} \end{aligned}
python · try it yourself
u, v = 2 + 3j, 4 - 1j
print(u + v, u * v, round(abs(v), 3))
(6+2j) (11+10j) 4.123

Exercise 2: Divide

Compute (5+5i)/(2+i)(5 + 5i)/(2 + i).

Answer

3+i3 + i

Solution
(5+5i)(2−i)(2+i)(2−i)=10−5i+10i−5i25=15+5i5=3+i\frac{(5 + 5i)(2 - i)}{(2 + i)(2 - i)} = \frac{10 - 5i + 10i - 5i^2}{5} = \frac{15 + 5i}{5} = 3 + i

Check: (3+i)(2+i)=6+3i+2i+i2=5+5i(3 + i)(2 + i) = 6 + 3i + 2i + i^2 = 5 + 5i.

Exercise 3: Powers of ii

Simplify i2027i^{2027}.

Answer

−i-i

Solution

The powers repeat every 4, so only the remainder of 2027÷42027 \div 4 matters: 2027=4⋅506+32027 = 4 \cdot 506 + 3, so i2027=i3=−ii^{2027} = i^3 = -i.

Exercise 4: Rotate a triangle

Rotate the triangle with corners (1,0)(1, 0), (3,0)(3, 0) and (2,2)(2, 2) by 90° counterclockwise about the origin using complex multiplication.

Answer

(0,1)(0, 1), (0,3)(0, 3), (−2,2)(-2, 2).

Solution

Multiplying by ii turns a+bia + bi into −b+ai-b + ai, which is a 90° rotation.

python · try it yourself
corners = [1 + 0j, 3 + 0j, 2 + 2j]
print([(int(z.real), int(z.imag)) for z in (c * 1j for c in corners)])
[(0, 1), (0, 3), (-2, 2)]

Exercise 5: Cube roots of unity

Find the three solutions of z3=1z^3 = 1 in the form a+bia + bi and check that they add up to 0.

Answer

11, −1/2+(3/2)i-1/2 + (\sqrt{3}/2)i, −1/2−(3/2)i-1/2 - (\sqrt{3}/2)i; their sum is 0.

Solution

They are e2πik/3e^{2\pi i k/3} for k=0,1,2k = 0, 1, 2, at angles 0°, 120° and 240°: cos⁡120∘=−1/2\cos 120^\circ = -1/2, sin⁡120∘=3/2\sin 120^\circ = \sqrt{3}/2. The sum is 1−1/2−1/2+(3/2−3/2)i=01 - 1/2 - 1/2 + (\sqrt{3}/2 - \sqrt{3}/2)i = 0.

python · try it yourself
import sympy as sp

z = sp.symbols('z')
roots = sp.solve(z**3 - 1, z)
print(roots, sp.simplify(sum(roots)))
[1, -1/2 - sqrt(3)*I/2, -1/2 + sqrt(3)*I/2] 0

Test yourself

What is (1+i)2(1 + i)^2?

  1. 2
  2. 2i2i
  3. 1+i21 + i^2
  4. 0

Multiplying a complex number by eiπ/3e^{i\pi/3} does what to its point in the plane?

  1. Doubles its length
  2. Reflects it in the real axis
  3. Rotates it 60° counterclockwise about the origin
  4. Moves it π/3\pi/3 units right

A polynomial with real coefficients has the root 2−5i2 - 5i. Which other number must also be a root?

  1. −2+5i-2 + 5i
  2. 2+5i2 + 5i
  3. 5−2i5 - 2i
  4. −2−5i-2 - 5i