Eigenvalues and eigenvectors

Most vectors change direction when a matrix multiplies them. A few special ones do not: they are only stretched or shrunk. These are eigenvectors, and the stretch factor is the eigenvalue λ:

A·v = λ·v

A 2×2 example

A = [[2, 1], [1, 2]] sends (1, 1) to (3, 3): the same direction, 3 times longer. So (1, 1) is an eigenvector with eigenvalue 3. It sends (1, −1) to (1, −1): eigenvalue 1.

Finding them exactly

For a 2×2 matrix, the eigenvalues solve the characteristic equation

λ² − (trace)·λ + det = 0

where the trace is a + d, the sum of the diagonal. For our A: λ² − 4λ + 3 = 0, so λ = 3 or 1. If the equation has no real roots, the matrix rotates every direction and has no real eigenvectors.

Power iteration

Multiply any starting vector by A again and again, rescaling each time. The direction with the biggest eigenvalue grows fastest and takes over.

A = [[2, 1],
     [1, 2]]
v = [1.0, 0.0]
for step in range(10):
    w = [A[0][0] * v[0] + A[0][1] * v[1], A[1][0] * v[0] + A[1][1] * v[1]]
    size = max(abs(w[0]), abs(w[1]))
    v = [w[0] / size, w[1] / size]
print("direction ≈", [round(x, 4) for x in v])
print("stretch ≈", round(size, 4))

trace, det = 2 + 2, 2 * 2 - 1 * 1
root = (trace * trace - 4 * det) ** 0.5
print("exact eigenvalues:", (trace + root) / 2, "and", (trace - root) / 2)
Open in compiler

After ten steps the vector points along (1, 1) and the stretch factor is 3, matching the exact answer.

Where it is used

  • Google's PageRank is the main eigenvector of the web's link matrix, found by power iteration.
  • PCA (principal component analysis) finds the directions in which data varies most: the eigenvectors of its covariance matrix.
  • Bridges and buildings vibrate at frequencies given by eigenvalues; engineers check them so that wind or footsteps cannot shake a structure apart.

Common mistakes

  • Counting the zero vector as an eigenvector. A·0 = λ·0 for every λ, so it tells you nothing; eigenvectors must be non-zero.

Quick check

1. If A·v = 3v, then v is an eigenvector with eigenvalue…
2. The eigenvalues of [[4, 0], [0, 7]] are…
3. Power iteration finds…

Practice problems for this lesson

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.