Eigenvalues by Power Iteration
Intuition
Most vectors change direction when multiplied by a matrix. Eigenvectors don't — they are only stretched: . If you multiply a random vector by again and again, the component along the eigenvector with the largest grows fastest and eventually dominates. That is power iteration.
Precise explanation
Algorithm:
- Start with (here: all ones).
- Repeat (normalise to avoid overflow).
- Estimate the eigenvalue with the Rayleigh quotient (for unit ).
- Stop when .
Convergence speed depends on : the closer to 1, the slower. Eigenvectors are only defined up to sign; fix a convention (here: make the entry with largest absolute value positive) so results are reproducible.
Worked example
has eigenvalues 3 and 1 with eigenvectors and . Starting from (1, 1) you are already on the dominant eigenvector: , normalised , Rayleigh quotient 3.
Common mistakes
- Not normalising → numbers overflow to
inf. - Starting with a vector orthogonal to the dominant eigenvector (e.g. (1,−1) above) — it never appears. (Real implementations start randomly.)
- Comparing eigenvectors without fixing the sign.
- Expecting the eigenvector to be as accurate as the eigenvalue. For symmetric matrices the Rayleigh quotient error is roughly the square of the vector error, so stopping on the eigenvalue leaves the vector accurate only to about .
Why this matters
Principal Component Analysis finds the dominant eigenvectors of a covariance matrix; Google's PageRank is power iteration on a link matrix; the spectral radius governs whether gradient descent and RNNs explode.
Library implementation
numpy.linalg.eigh (symmetric matrices) or numpy.linalg.eig compute all eigenvalues with
LAPACK; power iteration finds only the dominant one but needs nothing beyond matrix–vector
products, which is why it scales to huge sparse matrices (it is the idea behind PageRank). The
test compares your result with eigh on a symmetric matrix.
References
- Mathematics for Machine Learning — Marc Peter Deisenroth, A. Aldo Faisal, Cheng Soon Ong (Cambridge University Press) (
S009)