Eigendecomposition
Finding the directions a matrix only stretches, and using them to make powers of a matrix easy.
- Find eigenvalues from the characteristic equation
- Diagonalise a matrix and use it to compute powers
- See why repeated multiplication finds the dominant eigenvector
The first lesson met eigenvectors visually: directions that land back on their own span after the transformation, scaled by their eigenvalue.
\[A\mathbf{v} = \lambda\mathbf{v}\]Finding them
Move everything to one side: \((A - \lambda I)\mathbf{v} = \mathbf{0}\). A non-zero \(\mathbf{v}\) can only satisfy this if \(A - \lambda I\) crushes a direction — so its determinant is zero:
\[\det(A - \lambda I) = 0\]That characteristic equation gives the eigenvalues; each one then gives its eigenvector as the null space of \(A - \lambda I\). In code:
D, V = np.linalg.eig(A) # eigenvalues in D, eigenvectors as columns of V
The notebook’s quick checks are worth remembering: the eigenvalues of a diagonal or triangular matrix are just its diagonal entries, and larger random matrices typically have some complex eigenvalues — rotation hiding inside them.
Diagonalisation
Put the eigenvectors in the columns of \(V\) and the eigenvalues on the diagonal of \(\Lambda\). Then all the equations \(A\mathbf{v}_i = \lambda_i\mathbf{v}_i\) at once read \(AV = V\Lambda\), so
\[A = V \Lambda V^{-1}\]In the eigenvector basis, \(A\) is just a stretch along each axis. That makes powers cheap — the inner \(V^{-1}V\) pairs cancel:
\[A^{k} = V \Lambda^{k} V^{-1}\]A = np.random.randn(2, 2)
np.linalg.matrix_power(A, 3) # method 1
D, V = np.linalg.eig(A)
V @ np.linalg.matrix_power(np.diag(D), 3) @ np.linalg.inv(V) # method 2: same answer
Power iteration: the dominant direction wins
Apply \(A\) to a vector again and again. Write the vector in the eigenvector basis: each component gets multiplied by its own \(\lambda_i\) every step, so the component with the largest \(\vert \lambda\vert \) outgrows the rest. Renormalise each step to keep the length sensible, and the vector swings onto the dominant eigenvector.
How fast? The leftover component shrinks by \(\vert \lambda_2/\lambda_1\vert \) per step. Set the off-diagonal \(b\) near zero with \(a \approx d\) and the eigenvalues crowd together; convergence slows to a crawl. This is the algorithm behind Google’s original PageRank, and the reason \(A^3\) in the notebook has the same eigenvectors as \(A\) with the eigenvalues cubed.
Symmetric matrices are the friendly case
For a symmetric matrix (\(A = A^{\mathsf{T}}\)) the eigenvalues are always real and the eigenvectors are always perpendicular. Then \(V\) is orthogonal, \(V^{-1} = V^{\mathsf{T}}\), and
\[A = V\Lambda V^{\mathsf{T}} = \sum_i \lambda_i \mathbf{v}_i\mathbf{v}_i^{\mathsf{T}}\]— a sum of rank-one layers, one per eigenvalue. The notebook reconstructs a matrix exactly this way, adding layers one at a time.
Try it yourself. In the animation, make the eigenvalues equal and opposite — \(a = 1, d = -1, b = 0\) — and step. Why does the arrow never settle? Then in the notebook, run power iteration by hand for 50 steps on a symmetric 3×3 matrix and compare the result with the column of np.linalg.eig that has the largest eigenvalue.