TExcelTAD
Home › Calculus in Depth › Complex Numbers

Complex Numbers

This reference lesson covers complex numbers at the depth calculus needs: arithmetic, the complex plane, polar form, Euler's formula, De Moivre's theorem and roots. They return in second-order differential equations (complex roots of the characteristic equation) and they are a native type in Python and NumPy.

Definition and arithmetic

A complex number is z=a+biz = a + bi with real a,ba, b and i2=−1i^2 = -1. The real part is Re⁡z=a\operatorname{Re} z = a and the imaginary part Im⁡z=b\operatorname{Im} z = b. Arithmetic follows the usual algebra rules plus i2=−1i^2 = -1:

Operation Rule
Sum (a+bi)+(c+di)=(a+c)+(b+d)i(a + bi) + (c + di) = (a + c) + (b + d)i
Product (a+bi)(c+di)=(ac−bd)+(ad+bc)i(a + bi)(c + di) = (ac - bd) + (ad + bc)i
Conjugate zˉ=a−bi\bar{z} = a - bi, and z⋅zˉ=a2+b2z \cdot \bar{z} = a^2 + b^2
Quotient a+bic+di=(a+bi)(c−di)c2+d2\frac{a + bi}{c + di} = \frac{(a + bi)(c - di)}{c^2 + d^2}
Modulus ∣z∣=a2+b2\lvert z \rvert = \sqrt{a^2 + b^2}, ∣zw∣=∣z∣⋅∣w∣\lvert zw \rvert = \lvert z \rvert \cdot \lvert w \rvert

Every polynomial equation of degree nn has exactly nn complex roots counted with multiplicity (the Fundamental Theorem of Algebra), and the non-real roots of a real polynomial come in conjugate pairs. For example x2−4x+13=0x^2 - 4x + 13 = 0 gives x=4±16−522=2±3ix = \frac{4 \pm \sqrt{16 - 52}}{2} = 2 \pm 3i.

Python writes ii as j:

python · try it yourself
z, w = 3 + 4j, 1 - 2j
print("z + w =", z + w, "  z*w =", z * w, "  z/w =", z / w)
print("|z| =", abs(z), "  conj(z) =", z.conjugate(), "  z*conj(z) =", z * z.conjugate())

import numpy as np
print("roots of x^2 - 4x + 13:", np.roots([1, -4, 13]))
z + w = (4+2j)   z*w = (11-2j)   z/w = (-1+2j)
|z| = 5.0   conj(z) = (3-4j)   z*conj(z) = (25+0j)
roots of x^2 - 4x + 13: [2.+3.j 2.-3.j]

The complex plane and polar form

Plot a+bia + bi as the point (a,b)(a, b). With r=∣z∣r = \lvert z \rvert and θ=arg⁡z\theta = \arg z (the angle from the positive real axis, found with atan2⁡(b,a)\operatorname{atan2}(b, a), see Trigonometry Review):

z=r(cos⁡θ+isin⁡θ)z1z2=r1r2[cos⁡(θ1+θ2)+isin⁡(θ1+θ2)]multiply lengths, ADD anglesz1z2=r1r2[cos⁡(θ1−θ2)+isin⁡(θ1−θ2)]\begin{aligned} z &= r(\cos\theta + i\sin\theta) \\ z_1z_2 &= r_1r_2[\cos(\theta_1 + \theta_2) + i\sin(\theta_1 + \theta_2)] && \text{multiply lengths, ADD angles} \\ \frac{z_1}{z_2} &= \frac{r_1}{r_2}[\cos(\theta_1 - \theta_2) + i\sin(\theta_1 - \theta_2)] \end{aligned}

The product rule follows from the addition formulas for sine and cosine. So multiplying by a complex number of modulus 1 is a rotation.

Euler's formula and De Moivre

eiθ=cos⁡θ+isin⁡θsoz=reiθandeiπ+1=0e^{i\theta} = \cos\theta + i\sin\theta \qquad \text{so} \quad z = re^{i\theta} \quad \text{and} \quad e^{i\pi} + 1 = 0

One way to see it: substitute iθi\theta into the Maclaurin series of exe^x (see Taylor and Maclaurin Series). The even powers of iθi\theta are real and alternate in sign, building cos⁡θ\cos\theta; the odd powers are imaginary, building isin⁡θi\sin\theta. Repeated multiplication gives De Moivre's theorem:

[r(cos⁡θ+isin⁡θ)]n=rn(cos⁡nθ+isin⁡nθ)[r(\cos\theta + i\sin\theta)]^n = r^n(\cos n\theta + i\sin n\theta)

and the nn-th roots of w=reiφw = re^{i\varphi} are the nn numbers

r1/n⋅ei(φ+2πk)/n,k=0,1,…,n−1r^{1/n} \cdot e^{i(\varphi + 2\pi k)/n}, \qquad k = 0, 1, \ldots, n - 1

which sit evenly spaced on a circle.

python · try it yourself
import cmath, math

z = 1 + 1j
r, theta = cmath.polar(z)
print("polar:", round(r, 6), round(theta, 6), " (sqrt 2, pi/4)")
print("De Moivre: r^8 =", round(r**8, 9), " 8*theta in turns =", round(8 * theta / (2 * math.pi), 9), "  directly z^8 =", z**8)
print("e^(i pi) + 1 =", cmath.exp(1j * math.pi) + 1)

roots = [cmath.exp(2j * math.pi * k / 3) * 8 ** (1/3) for k in range(3)]
for k, w in enumerate(roots):
    print(f"cube root {k} of 8: {w.real:+.4f} {w.imag:+.4f}i   cubed = {w**3:.4f}")
polar: 1.414214 0.785398  (sqrt 2, pi/4)
De Moivre: r^8 = 16.0  8*theta in turns = 1.0   directly z^8 = (16+0j)
e^(i pi) + 1 = 1.2246467991473532e-16j
cube root 0 of 8: +2.0000 +0.0000i   cubed = 8.0000+0.0000j
cube root 1 of 8: -1.0000 +1.7321i   cubed = 8.0000-0.0000j
cube root 2 of 8: -1.0000 -1.7321i   cubed = 8.0000-0.0000j

eiπ+1e^{i\pi} + 1 comes out as 1.2⋅10−16⋅i1.2 \cdot 10^{-16} \cdot i instead of 0: rounding error in π\pi, not a failure of Euler's formula. The gentle survey is Complex Numbers.

In calculus

When y′′+by′+cy=0y'' + by' + cy = 0 has a characteristic equation with roots α±βi\alpha \pm \beta i, Euler's formula turns e(α+iβ)te^{(\alpha + i\beta)t} into eαt(cos⁡βt+isin⁡βt)e^{\alpha t}(\cos\beta t + i\sin\beta t), and the real solutions are eαtcos⁡βte^{\alpha t}\cos\beta t and eαtsin⁡βte^{\alpha t}\sin\beta t: damped oscillations. See Second-Order Linear Equations.

In software

  • 2D rotation. Multiplying the point x+yix + yi by eiθe^{i\theta} rotates it by θ\theta about the origin, the same as the 2×22 \times 2 rotation matrix. Some 2D engines store orientations as unit complex numbers; quaternions are the 3D generalisation.
  • Signals and the FFT. The discrete Fourier transform writes a signal as a sum of e2πikn/Ne^{2\pi ikn/N}, the NN-th roots of unity. The FFT computes it in O(Nlog⁡N)O(N \log N) by exploiting their symmetry; audio, image compression and fast polynomial multiplication rely on it.
  • Fractals. The Mandelbrot set iterates z←z2+cz \leftarrow z^2 + c.
python · try it yourself
import numpy as np

point = 2 + 1j
print("rotate (2, 1) by 90 degrees:", point * np.exp(1j * np.pi / 2).round(12))

t = np.arange(8)
signal = 3 * np.cos(2 * np.pi * t / 8) + np.sin(2 * np.pi * 2 * t / 8)
spectrum = np.fft.fft(signal).round(6)
print("FFT magnitudes:", np.abs(spectrum).round(3).tolist())
rotate (2, 1) by 90 degrees: (-1+2j)
FFT magnitudes: [0.0, 12.0, 4.0, 0.0, 0.0, 0.0, 4.0, 12.0]

The FFT finds frequency 1 with weight 3 (magnitude 3⋅8/2=123 \cdot 8/2 = 12) and frequency 2 with weight 1 (magnitude 4), each mirrored at N−kN - k.

Exercises

Exercise 1: Arithmetic

Compute (2−3i)(4+i)(2 - 3i)(4 + i) and 5+5i1+2i\frac{5 + 5i}{1 + 2i}.

Answer

11−10i11 - 10i and 3−i3 - i.

Solution
(2−3i)(4+i)=8+2i−12i−3i2=8−10i+3=11−10i(5+5i)(1−2i)1+4=5−10i+5i−10i25=15−5i5=3−i\begin{aligned} (2 - 3i)(4 + i) &= 8 + 2i - 12i - 3i^2 = 8 - 10i + 3 = 11 - 10i \\ \frac{(5 + 5i)(1 - 2i)}{1 + 4} &= \frac{5 - 10i + 5i - 10i^2}{5} = \frac{15 - 5i}{5} = 3 - i \end{aligned}

Exercise 2: Polar form and a power

Write −2+2i-2 + 2i in polar form and compute (−2+2i)6(-2 + 2i)^6.

Answer

22⋅e3πi/42\sqrt{2} \cdot e^{3\pi i/4}; the sixth power is 512i512i.

Solution

r=8=22r = \sqrt{8} = 2\sqrt{2}, θ=atan2⁡(2,−2)=3π/4\theta = \operatorname{atan2}(2, -2) = 3\pi/4. Then r6=83=512r^6 = 8^3 = 512 and 6θ=9π/2≡π/26\theta = 9\pi/2 \equiv \pi/2, so the result is 512(cos⁡π/2+isin⁡π/2)=512i512(\cos \pi/2 + i\sin \pi/2) = 512i.

python · try it yourself
print((-2 + 2j) ** 6)
(-0+512j)

The -0 is a signed floating-point zero, still 0.

Exercise 3: Fourth roots

Find all fourth roots of −16-16.

Answer

2±2 i\sqrt{2} \pm \sqrt{2}\,i and −2±2 i-\sqrt{2} \pm \sqrt{2}\,i.

Solution

−16=16eiπ-16 = 16e^{i\pi}. The roots are 2ei(π+2πk)/42e^{i(\pi + 2\pi k)/4} for k=0,…,3k = 0, \ldots, 3: angles π/4,3π/4,5π/4,7π/4\pi/4, 3\pi/4, 5\pi/4, 7\pi/4, giving 2(±22±22i)=±2±2 i2\left(\pm\frac{\sqrt{2}}{2} \pm \frac{\sqrt{2}}{2}i\right) = \pm\sqrt{2} \pm \sqrt{2}\,i.

Exercise 4: Rotate a polygon (code)

Rotate the triangle with vertices (1,0)(1, 0), (3,0)(3, 0), (2,2)(2, 2) by 60∘60^\circ about the point (2,1)(2, 1) using complex numbers: z↦c+(z−c)eiθz \mapsto c + (z - c)e^{i\theta}. Print the new vertices rounded to 4 decimals.

Answer

(2.366,−0.366)(2.366, -0.366), (3.366,1.366)(3.366, 1.366), (1.134,1.5)(1.134, 1.5) (to 3 decimals).

Solution
python · try it yourself
import cmath, math

c = 2 + 1j
rot = cmath.exp(1j * math.radians(60))
for z in [1 + 0j, 3 + 0j, 2 + 2j]:
    w = c + (z - c) * rot
    print(round(w.real, 4), round(w.imag, 4))
2.366 -0.366
3.366 1.366
1.134 1.5

Test yourself

What is i7i^7?

  1. −i-i
  2. ii
  3. 11
  4. −1-1

Multiplying two complex numbers in polar form…

  1. adds moduli and multiplies angles
  2. multiplies moduli and adds angles
  3. multiplies moduli and multiplies angles
  4. adds both

A real-coefficient polynomial has the root 1−4i1 - 4i. Which other number must be a root?

  1. −1+4i-1 + 4i
  2. 4−i4 - i
  3. 1+4i1 + 4i
  4. None necessarily