Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 1: Math FoundationsLinear Algebra

Eigenvalues and eigenvectors

P1.B1245 min●●○ IntermediateReviewed Nov 30, 2026

Why this matters for machine learning

Eigenvectors are the directions a matrix only stretches, and the eigenvalues say by how much, so they predict what happens when the same matrix is applied again and again and show which directions matter most in a data set.

  • PCA finds the eigenvectors of the covariance matrix: they are the directions of most variance, and the eigenvalues are the variances along them. (P3.C3: Principal Component Analysis, coming soon)
  • A deep chain or a recurrent network multiplies by a weight matrix again and again, so the gradient grows or fades by about ∣λ∣|\lambda| per step: exploding and vanishing gradients. (P4.16: Vanishing and exploding gradients, coming soon)
  • Backpropagation through time in a recurrent network multiplies by the same matrix at every time step, which is why gradients across long sequences fade. (P6.6: Backprop through time, coming soon)
  • Gradient descent is slow on a bowl whose curvature is very different in different directions: the ratio of the largest to the smallest eigenvalue of the Hessian is the ill-conditioning. (P1.F3: Gradient descent)
  • Where the gradient is zero, a positive definite Hessian (all eigenvalues above 00) means the bottom of a bowl, and eigenvalues of both signs mean a saddle. (P1.C8: The Hessian, curvature and Taylor approximation)
  • Ridge regression adds λI\lambda\mathbf{I} to X⊤X\mathbf{X}^\top\mathbf{X}, which lifts every eigenvalue by λ\lambda and so makes the matrix invertible. (P3.A6: Regularization: L1 and L2, coming soon)

Before this: Matrices as data and as transformations, The determinant, Transpose, symmetric and orthogonal matrices

After this lesson you can

  • Say what Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} means, why v\mathbf{v} must not be the zero vector, and read an eigenvalue as a stretch (λ>1\lambda>1), a shrink (0<λ<10<\lambda<1), a flip (λ<0\lambda<0) or a squash (λ=0\lambda=0)
  • Find the eigenvalues and eigenvectors of a 2×22\times2 matrix from λ2−(trace)λ+det⁡=0\lambda^2-(\text{trace})\lambda+\det=0, and check them with trace == sum and det⁡=\det= product
  • Recognise the cases for a real 2×22\times2 matrix (two directions, one repeated direction, every direction, none) and explain Akx\mathbf{A}^k\mathbf{x}, A=VΛV−1\mathbf{A}=\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1} and why the largest ∣λ∣|\lambda| decides growth or decay
  • State the spectral theorem for symmetric matrices, test positive (semi-)definiteness with eigenvalues, and use np.linalg.eig and np.linalg.eigh

In P1.B5 you saw that a matrix warps the whole plane: most arrows are turned and stretched at the same time. In P1.B8 you met a number, the determinant, that tells you how much area is stretched. But a single number cannot say how the plane is warped. Is there a simpler way to see what a matrix does?

There is, and it comes from asking: are there any directions that the matrix does not turn? If a matrix sends an arrow to a longer, shorter or reversed arrow along the same line, the arrow is easy to understand: the matrix just multiplies it by a number. Those special directions and their numbers are the eigenvectors and eigenvalues (from the German eigen, “own” or “characteristic”: they are the matrix’s own directions). This lesson shows how to find them, what they tell you, and why they predict what happens when you apply a matrix again and again.

A direction that only stretches

Take the symmetric matrix of P1.B8:

A=(2112)\mathbf{A}=\begin{pmatrix}2&1\\1&2\end{pmatrix}

Apply it to three vectors:

A(10)=(21)A(11)=(33)=3(11)A(1−1)=(1−1)=1(1−1)\begin{aligned} \mathbf{A}\begin{pmatrix}1\\0\end{pmatrix}&=\begin{pmatrix}2\\1\end{pmatrix}\\ \mathbf{A}\begin{pmatrix}1\\1\end{pmatrix}&=\begin{pmatrix}3\\3\end{pmatrix}=3\begin{pmatrix}1\\1\end{pmatrix}\\ \mathbf{A}\begin{pmatrix}1\\-1\end{pmatrix}&=\begin{pmatrix}1\\-1\end{pmatrix}=1\begin{pmatrix}1\\-1\end{pmatrix} \end{aligned}

The first vector is turned: (1,0)(1,0) points along the xx-axis, and (2,1)(2,1) points somewhere else. But (1,1)(1,1) lands on (3,3)(3,3), the same direction, three times as long, and (1,−1)(1,-1) lands on itself. These two directions are the only ones that A\mathbf{A} does not turn.

That is the definition. A non-zero vector v\mathbf{v} is an eigenvector of a square matrix A\mathbf{A} if

Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v}

for some number λ\lambda, called its eigenvalue (the Greek letter lambda). So (1,1)(1,1) is an eigenvector of A\mathbf{A} with eigenvalue 33, and (1,−1)(1,-1) is one with eigenvalue 11. Only square matrices have eigenvectors: Av\mathbf{A}\mathbf{v} must have the same length as v\mathbf{v} to be compared with it.

Why is the zero vector excluded? Because A0=0=λ0\mathbf{A}\mathbf{0}=\mathbf{0}=\lambda\mathbf{0} is true for every matrix and every λ\lambda, so it would tell you nothing. Notice the difference: the vector 0\mathbf{0} is never an eigenvector, but the number λ=0\lambda=0 is allowed as an eigenvalue (you will see what it means below).

The widget draws the eigen-directions of any 2×22\times2 matrix. It starts with the matrix above.

Which directions does the matrix only stretch?

−4−224−4−224λ₁ = 3λ₂ = 1vAv
A = 21 12
trace = 4, det = 3, so the characteristic equation is λ² − 4λ + 3 = 0
λ₁ = 3, λ₂ = 1
trace = 4 = 3 + 1, det = 3 = 3 × 1
direction 1: (1, 1) for λ = 3. Check: A(1, 1) = (3, 3) = 3 × (1, 1)
direction 2: (1, −1) for λ = 1. Check: A(1, −1) = (1, −1) = 1 × (1, −1)
v = (1.5, 0.5), Av = (3.5, 2.5)

v is not on an eigen-direction, so Av points a different way: Av is v turned by 17.1° counterclockwise and rescaled. The grid line through v is not kept on its line.

Thin blue lines: the grid after the warp. Grey lines: the original grid. Green lines: the eigen-directions (two, one or none), labelled with their eigenvalues. The blue arrow is v (drag its tip, or use the arrow keys) and the pink arrow is Av. Entries are shown rounded to 3 decimals.

Eigen warp. The thin blue lines are the grid after the matrix warps the plane. The green lines are the eigen-directions (two, one or none), each labelled with its eigenvalue; the solid one has the larger eigenvalue. The blue arrow is a test vector v (drag its tip, or focus it and use the arrow keys) and the pink arrow is Av. The readout shows the characteristic equation, the eigenvalues, the eigenvectors with a check, and a status line that says when Av = λv. The buttons put v exactly on an eigen-direction, and the presets load the matrices of this lesson.

Things to try:

  1. At the start, the green solid line runs along (1,1)(1,1) with λ1=3\lambda_1=3 and the dashed one along (1,−1)(1,-1) with λ2=1\lambda_2=1. The vector v=(1.5,0.5)\mathbf{v}=(1.5,0.5) is on neither, so the pink Av=(3.5,2.5)\mathbf{A}\mathbf{v}=(3.5,2.5) points a different way, closer to the (1,1)(1,1) line.
  2. Press Put v on eigen-direction 1. Now Av\mathbf{A}\mathbf{v} is on the same line, three times as long, and the status says “Av = λv with λ = 3”. Press Put v on eigen-direction 2: Av=v\mathbf{A}\mathbf{v}=\mathbf{v}.
  3. Press Diagonal (λ=2\lambda=2 and λ=0.5\lambda=0.5): the eigen-directions are the two axes. Press Triangular: the directions are (1,1)(1,1) for λ=3\lambda=3 and (1,0)(1,0) for λ=2\lambda=2, and they are not perpendicular.
  4. Press Shear: there is only one green line. Press Rotate 30°: there is none, and the status says so. Press Scale (2I): every direction is an eigen-direction.
  5. Press Project (λ=1\lambda=1 and λ=0\lambda=0) and put v\mathbf{v} on eigen-direction 2: Av\mathbf{A}\mathbf{v} is the zero vector (a squash). Press Reflect (λ=1\lambda=1 and λ=−1\lambda=-1) and do the same: Av=−v\mathbf{A}\mathbf{v}=-\mathbf{v} (a flip).
  6. Start from Symmetric and use the sliders to make A12A_{12} and A21A_{21} equal, non-zero and different from 11: the two green lines stay perpendicular. Then make them different (for example A12=2A_{12}=2, A21=1A_{21}=1): the lines are no longer perpendicular.

Intuition

Picture the plane as a sheet of rubber with a grid printed on it. A matrix grabs the sheet and deforms it: stretching, squashing, turning, shearing. Most printed arrows end up pointing a new way. But for many matrices there are one or two lines through the origin that stay lines: arrows along them are only made longer, shorter, or reversed. Those lines are the eigen-directions, and they are the “grain” of the deformation.

The analogy breaks in three places. A sheet of rubber cannot be turned over by pulling, but a negative eigenvalue flips an arrow to the other side of the origin. Some deformations have no such grain at all: a rotation turns every direction. And in a shear there is one grain line, not two.

Math

Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} with v≠0\mathbf{v}\ne\mathbf{0}. Here A\mathbf{A} is n×nn\times n, v\mathbf{v} is a vector, and λ\lambda is a scalar (a plain number). The equation can be rearranged to (A−λI)v=0(\mathbf{A}-\lambda\mathbf{I})\mathbf{v}=\mathbf{0}, which is how you solve for them (next sections).

The set of all vectors v\mathbf{v} with Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v}, together with 0\mathbf{0}, is the eigenspace of λ\lambda. For the matrix above, the eigenspace of λ=3\lambda=3 is the line {t(1,1)}\{t(1,1)\}.

Code

import numpy as np

A = np.array([[2, 1], [1, 2]])
print(A @ np.array([1, 1]))    # [3 3]  = 3 * (1, 1)
print(A @ np.array([1, -1]))   # [ 1 -1] = 1 * (1, -1)
print(A @ np.array([1, 0]))    # [2 1]  is not a multiple of (1, 0)

The NumPy section below shows how to ask the computer for all the eigenvectors at once.

What the eigenvalue tells you

Along an eigen-direction the matrix is just multiplication by a number, so λ\lambda says exactly what happens to that line:

  • λ>1\lambda>1: stretched (like λ=3\lambda=3 above).
  • λ=1\lambda=1: left alone (like (1,−1)(1,-1) above).
  • 0<λ<10<\lambda<1: shrunk towards the origin.
  • λ<0\lambda<0: flipped to the other side of the origin, and stretched or shrunk by ∣λ∣|\lambda|.
  • λ=0\lambda=0: squashed onto the origin. Every vector on that line is sent to 0\mathbf{0}, so the line is part of the null space (P1.B7). A square matrix has eigenvalue 00 exactly when it squashes something, that is, when det⁡=0\det=0 and it has no inverse (P1.B8, P1.B9).

An eigenvector is a direction, not one special arrow. If Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} then for any number tt,

A(tv)=t Av=tλv=λ(tv)\mathbf{A}(t\mathbf{v})=t\,\mathbf{A}\mathbf{v}=t\lambda\mathbf{v}=\lambda(t\mathbf{v})

so every non-zero multiple of v\mathbf{v}, including −v-\mathbf{v}, is an eigenvector with the same λ\lambda. (1,1)(1,1), (2,2)(2,2) and (−0.5,−0.5)(-0.5,-0.5) are all eigenvectors for λ=3\lambda=3. That is why the widget draws a line, and why software returns eigenvectors scaled to length 11 (with an arbitrary sign).

Different eigenvalues give different directions. Suppose v2\mathbf{v}_2 were a multiple of v1\mathbf{v}_1, say v2=tv1\mathbf{v}_2=t\mathbf{v}_1, with eigenvalues λ1\lambda_1 and λ2\lambda_2. Then Av2=λ2v2\mathbf{A}\mathbf{v}_2=\lambda_2\mathbf{v}_2, but also Av2=tλ1v1=λ1v2\mathbf{A}\mathbf{v}_2=t\lambda_1\mathbf{v}_1=\lambda_1\mathbf{v}_2. So (λ2−λ1)v2=0(\lambda_2-\lambda_1)\mathbf{v}_2=\mathbf{0}, which forces λ1=λ2\lambda_1=\lambda_2. Eigenvectors for different eigenvalues are never on the same line (in higher dimensions, they are linearly independent).

Finding eigenvalues of a 2×2 matrix

Start from Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} and move everything to one side: (A−λI)v=0(\mathbf{A}-\lambda\mathbf{I})\mathbf{v}=\mathbf{0}. We want a non-zero v\mathbf{v} that A−λI\mathbf{A}-\lambda\mathbf{I} sends to 0\mathbf{0}. A matrix does that only if it squashes the plane, and P1.B8 says that happens exactly when its determinant is 00:

det⁡(A−λI)=0\det(\mathbf{A}-\lambda\mathbf{I})=0

This is the characteristic equation. For A=(abcd)\mathbf{A}=\begin{pmatrix}a&b\\c&d\end{pmatrix}:

det⁡(a−λbcd−λ)\det\begin{pmatrix}a-\lambda&b\\c&d-\lambda\end{pmatrix} det⁡=(a−λ)(d−λ)−bc=λ2−(a+d)λ+(ad−bc)\begin{aligned} \phantom{\det}&=(a-\lambda)(d-\lambda)-bc\\ &=\lambda^2-(a+d)\lambda+(ad-bc) \end{aligned}

So the eigenvalues solve

λ2−(trace) λ+det⁡=0\lambda^2-(\text{trace})\,\lambda+\det=0

where trace=a+d\text{trace}=a+d and det⁡=ad−bc\det=ad-bc.

Example. For (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix} the trace is 44 and the determinant is 4−1=34-1=3, so λ2−4λ+3=(λ−1)(λ−3)=0\lambda^2-4\lambda+3=(\lambda-1)(\lambda-3)=0 and λ=3\lambda=3 or λ=1\lambda=1. (The widget shows this equation for every matrix.)

Then find the eigenvector for each λ\lambda by solving (A−λI)v=0(\mathbf{A}-\lambda\mathbf{I})\mathbf{v}=\mathbf{0}:

  • λ=3\lambda=3: (−111−1)v=0\begin{pmatrix}-1&1\\1&-1\end{pmatrix}\mathbf{v}=\mathbf{0}. Both rows say −x+y=0-x+y=0, so y=xy=x and v=(1,1)\mathbf{v}=(1,1).
  • λ=1\lambda=1: (1111)v=0\begin{pmatrix}1&1\\1&1\end{pmatrix}\mathbf{v}=\mathbf{0}. Both rows say x+y=0x+y=0, so v=(1,−1)\mathbf{v}=(1,-1).

In both cases the two rows are copies of each other. That is not a coincidence: A−λI\mathbf{A}-\lambda\mathbf{I} is singular, so its rows are dependent. If your two rows are not multiples of each other, you have made an arithmetic slip in λ\lambda. It is also a quick check: always confirm with Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v}.

Trace and determinant give a shortcut. The two roots of λ2−(trace)λ+det⁡=0\lambda^2-(\text{trace})\lambda+\det=0 add up to the trace and multiply to the determinant. So for a 2×22\times2 matrix:

λ1+λ2=trace,λ1λ2=det⁡\lambda_1+\lambda_2=\text{trace},\qquad \lambda_1\lambda_2=\det

For the example, 3+1=43+1=4 and 3⋅1=33\cdot1=3. This is the fact that P1.B8 previewed: the determinant is the product of the eigenvalues, which makes sense because the matrix stretches one direction by 33 and another by 11, so areas are multiplied by 3⋅13\cdot1. If you know the trace and the determinant, look for two numbers with that sum and product. And if det⁡=0\det=0, one eigenvalue is 00.

The quadratic formula gives λ=12(trace±trace2−4det⁡)\lambda=\tfrac12\bigl(\text{trace}\pm\sqrt{\text{trace}^2-4\det}\bigr), and the number under the root, trace2−4det⁡=(a−d)2+4bc\text{trace}^2-4\det=(a-d)^2+4bc, decides the case:

  • positive: two different real eigenvalues, so two eigen-directions;
  • zero: one repeated eigenvalue;
  • negative: no real eigenvalues. The matrix has no real eigen-directions: it turns every direction.

Bigger matrices work the same way: det⁡(A−λI)=0\det(\mathbf{A}-\lambda\mathbf{I})=0 is a polynomial of degree nn, so an n×nn\times n matrix has at most nn eigenvalues (counting repeats, and allowing complex ones there are exactly nn), and for any square matrix the sum of the eigenvalues is the trace and their product is the determinant. For instance, (200034049)\begin{pmatrix}2&0&0\\0&3&4\\0&4&9\end{pmatrix} has eigenvalues 1111, 22 and 11, with sum 14=2+3+914=2+3+9 and product 22=det⁡22=\det. For large matrices software does not solve the polynomial: there is no general formula (using roots and the four basic operations) for the roots of a polynomial of degree 55 or more, so it uses iterative numerical methods.

Here is every kind of behaviour you can meet. All of them are presets in the widget, so try each one.

  • Diagonal, (2000.5)\begin{pmatrix}2&0\\0&0.5\end{pmatrix}: the eigenvalues are the diagonal entries 22 and 0.50.5, with eigenvectors (1,0)(1,0) and (0,1)(0,1). It stretches xx by 22 and shrinks yy to half.
  • Triangular, (2103)\begin{pmatrix}2&1\\0&3\end{pmatrix}: det⁡(A−λI)=(2−λ)(3−λ)\det(\mathbf{A}-\lambda\mathbf{I})=(2-\lambda)(3-\lambda), so the eigenvalues are again the diagonal entries (this holds for every triangular matrix). The eigenvectors are (1,0)(1,0) for λ=2\lambda=2 and (1,1)(1,1) for λ=3\lambda=3: check A(1,1)=(3,3)\mathbf{A}(1,1)=(3,3). They are not perpendicular.
  • Projection onto the line y=xy=x, (0.50.50.50.5)\begin{pmatrix}0.5&0.5\\0.5&0.5\end{pmatrix}: trace 11, det⁡=0\det=0, so λ2−λ=0\lambda^2-\lambda=0 and λ=1\lambda=1 or λ=0\lambda=0. The line (1,1)(1,1) is kept (λ=1\lambda=1) and (1,−1)(1,-1) is squashed to 0\mathbf{0} (λ=0\lambda=0). This is the projection of P1.B5 and P1.B11, and every eigenvalue of a projection is 11 or 00.
  • Reflection in the line y=xy=x, (0110)\begin{pmatrix}0&1\\1&0\end{pmatrix}: trace 00, det⁡=−1\det=-1, so λ2−1=0\lambda^2-1=0 and λ=1\lambda=1 or λ=−1\lambda=-1. (1,1)(1,1) is kept and (1,−1)(1,-1) is flipped to (−1,1)(-1,1).
  • Scaling by 2, (2002)=2I\begin{pmatrix}2&0\\0&2\end{pmatrix}=2\mathbf{I}: Av=2v\mathbf{A}\mathbf{v}=2\mathbf{v} for every v\mathbf{v}, so every direction is an eigen-direction. The eigenvalue 22 is repeated, and A−2I\mathbf{A}-2\mathbf{I} is the zero matrix.
  • Shear, (1101)\begin{pmatrix}1&1\\0&1\end{pmatrix}: λ2−2λ+1=(λ−1)2\lambda^2-2\lambda+1=(\lambda-1)^2, so λ=1\lambda=1 twice. But A−I=(0100)\mathbf{A}-\mathbf{I}=\begin{pmatrix}0&1\\0&0\end{pmatrix} forces y=0y=0, so the only eigen-direction is (1,0)(1,0). A matrix with too few eigen-directions is called defective. Notice that a repeated eigenvalue does not always mean a defect: 2I2\mathbf{I} has the same repeated eigenvalue and every direction.
  • Rotation by 90∘90^\circ, (0−110)\begin{pmatrix}0&-1\\1&0\end{pmatrix}: trace 00, det⁡=1\det=1, so λ2+1=0\lambda^2+1=0, which has no real solution. No real direction is kept. (A rotation by 0∘0^\circ or 180∘180^\circ is I\mathbf{I} or −I-\mathbf{I}, which keep every line. Any other rotation turns every direction.)

So a real 2×22\times2 matrix has two eigen-directions, or one (a defective matrix such as a shear), or every direction (a multiple of I\mathbf{I}), or none (complex eigenvalues).

Go deeper Complex eigenvalues: what a rotation does have

For the quarter turn R=(0−110)\mathbf{R}=\begin{pmatrix}0&-1\\1&0\end{pmatrix} the equation λ2+1=0\lambda^2+1=0 has the complex solutions λ=i\lambda=i and λ=−i\lambda=-i, where i2=−1i^2=-1. The vector (1,−i)(1,-i), which has a complex entry, satisfies R(1,−i)=(i,1)=i (1,−i)\mathbf{R}(1,-i)=(i,1)=i\,(1,-i), so it is an eigenvector for λ=i\lambda=i. It is not an arrow in the real plane, which is why the plane has no real eigen-direction. A rotation by an angle θ\theta has eigenvalues cos⁡θ±isin⁡θ\cos\theta\pm i\sin\theta, both of size 11 (the matrix keeps lengths), and the angle of the complex number is the turn. Applying the rotation kk times multiplies the eigenvalue kk times, and i4=1i^4=1 says four quarter turns bring you back.

In general a real matrix with a complex eigenvalue pair p±qip\pm qi behaves over many steps like a spiral: on average it turns by the angle of p+qip+qi per step and scales by p2+q2=det⁡\sqrt{p^2+q^2}=\sqrt{\det} per step (exactly so for a pure turn-and-scale matrix; for other matrices the turn and stretch vary from vector to vector). NumPy returns such eigenvalues as complex numbers. They matter in practice (the eigenvalues of recurrent networks can be complex), but this lesson only needs the real picture.

New matrices from old

If Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} with v≠0\mathbf{v}\ne\mathbf{0}, then the same v\mathbf{v} is an eigenvector of these related matrices, with these eigenvalues:

  • A2\mathbf{A}^2, A3\mathbf{A}^3, …: λ2\lambda^2, λ3\lambda^3, … Indeed A2v=A(λv)=λAv=λ2v\mathbf{A}^2\mathbf{v}=\mathbf{A}(\lambda\mathbf{v})=\lambda\mathbf{A}\mathbf{v}=\lambda^2\mathbf{v}.
  • cAc\mathbf{A}: cλc\lambda. And A+cI\mathbf{A}+c\mathbf{I}: λ+c\lambda+c.
  • A−1\mathbf{A}^{-1}, if A\mathbf{A} is invertible: 1/λ1/\lambda. (An invertible matrix has no zero eigenvalue, so this is always defined.) For (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix} the inverse has eigenvalues 13\tfrac13 and 11.

One more fact: A⊤\mathbf{A}^\top has the same eigenvalues as A\mathbf{A} (the characteristic equation is the same, because det⁡M⊤=det⁡M\det\mathbf{M}^\top=\det\mathbf{M}), but usually different eigenvectors. For the triangular matrix above, A\mathbf{A} has eigenvector (1,0)(1,0) for λ=2\lambda=2, while A⊤=(2013)\mathbf{A}^\top=\begin{pmatrix}2&0\\1&3\end{pmatrix} has (1,−1)(1,-1) for λ=2\lambda=2.

The rules above do not extend to sums and products of different matrices: the eigenvalues of A+B\mathbf{A}+\mathbf{B} are not the sums of eigenvalues, and those of AB\mathbf{A}\mathbf{B} are not the products (see the mistakes at the end).

Applying a matrix again and again

Now the idea that makes eigenvectors so useful. If x\mathbf{x} happens to be an eigenvector, Akx=λkx\mathbf{A}^k\mathbf{x}=\lambda^k\mathbf{x}: applying the matrix kk times just multiplies by λ\lambda each time. For any other x\mathbf{x}, write it as a mix of the two eigenvectors, x=c1v1+c2v2\mathbf{x}=c_1\mathbf{v}_1+c_2\mathbf{v}_2. Since A\mathbf{A} acts on each part by its own number,

Akx=c1λ1kv1+c2λ2kv2\mathbf{A}^k\mathbf{x}=c_1\lambda_1^k\mathbf{v}_1+c_2\lambda_2^k\mathbf{v}_2

For A=(2112)\mathbf{A}=\begin{pmatrix}2&1\\1&2\end{pmatrix} and x=(1,0)=12(1,1)+12(1,−1)\mathbf{x}=(1,0)=\tfrac12(1,1)+\tfrac12(1,-1) this is

Akx=12 3k(11)+12(1−1)\mathbf{A}^k\mathbf{x}=\tfrac12\,3^k\begin{pmatrix}1\\1\end{pmatrix}+\tfrac12\begin{pmatrix}1\\-1\end{pmatrix}

The second part never changes size (its λ\lambda is 11), but the first part is multiplied by 33 every step. The first steps are (2,1)(2,1), (5,4)(5,4), (14,13)(14,13), and by k=6k=6 it is (365,364)(365,364): almost exactly along (1,1)(1,1). The part with the biggest ∣λ∣|\lambda| takes over. This is what the next widget shows.

Apply the matrix again and again

−6−4−2246−6−4−2246xA²xλ₁ = 3λ₂ = 1
eigenvalues: λ₁ = 3, λ₂ = 1
x = (1, 0)
A²x = (5, 4), length = 6.403124
length of A²x ÷ length of Ax = 2.864
angle between A²x and the solid green line = 6.3°

x is a mix of the two eigen-directions. Each step multiplies the part along the solid green line by λ = 3 and the other part by 1. Since |3| is bigger than |1|, the first part wins: x swings toward the solid green line (after 2 steps it is 6.3° from it), and the length is multiplied by about |λ| = 3 per step, so it grows.

The blue handle is the start x (drag it, or use the arrow keys). Grey dots: the earlier steps, joined by a line. The pink arrow is the latest result. Green lines: the eigen-directions, the solid one for the larger |λ|. In “direction only” mode the true lengths are still in the readout.

Power steps. Choose a matrix and drag the blue handle x. The grey dots and line are x, Ax, A²x and so on; the pink arrow is the latest one, A^k x. The green lines are the eigen-directions, the solid one for the larger |λ|. The slider sets the number of steps k. The readout gives the length of the latest result, the length ratio from one step to the next, and the angle to the solid green line. The status explains what happens for this matrix. Tick the box to show every point at length 1 so that only the direction is visible.

Things to try:

  1. At the start (A\mathbf{A} of this lesson, x=(1,0)\mathbf{x}=(1,0)) move the slider from 00 to 66. The pink arrow swings to the solid green line, the ratio of lengths approaches λ1=3\lambda_1=3, and the angle to the line falls towards 00.
  2. Press Growing (λ=1.2\lambda=1.2 and 0.50.5): the length grows slowly, about 1.21.2 times per step. Press Shrinking (0.750.75 and 0.250.25): everything fades to the origin. Press Flipping (−1.2-1.2 and 0.50.5): the arrow also jumps to the other side of the origin at every step.
  3. Tick Direction only to see the swing even when the lengths become huge.
  4. Put x\mathbf{x} exactly on a green line (for the first matrix, (1,1)(1,1) or (1,−1)(1,-1)): it never leaves the line. On the second line it will never swing, because it has no part along the first.
  5. Press Shear and drag x\mathbf{x} off the horizontal green line (for example to (1,1)(1,1)): λ=1\lambda=1 twice, yet the length keeps growing, and the direction creeps towards the one green line only slowly. Press Spiral: no real eigen-direction, and the vector turns while it shrinks. Press Reflect (11 and −1-1): the two sizes tie, so nothing wins.

What this says about ∣λ∣|\lambda|. For a matrix whose eigenvalues are real and different:

  • ∣λ∣>1|\lambda|>1: that part grows by about ∣λ∣|\lambda| per step.
  • ∣λ∣<1|\lambda|<1: that part shrinks towards 0\mathbf{0}.
  • ∣λ∣=1|\lambda|=1: that part keeps its size.

If every eigenvalue has ∣λ∣<1|\lambda|<1, then Akx→0\mathbf{A}^k\mathbf{x}\to\mathbf{0} for every x\mathbf{x}. If at least one has ∣λ∣>1|\lambda|>1, a typical x\mathbf{x} (one with some part along that direction) grows without bound. The largest ∣λ∣|\lambda| is called the spectral radius of A\mathbf{A}. For the first widget matrix, Akx\mathbf{A}^k\mathbf{x} grows like 3k3^k, and A−1\mathbf{A}^{-1} (eigenvalues 13\tfrac13 and 11) shrinks the first part by 33 per step.

A warning from the shear. For (1101)\begin{pmatrix}1&1\\0&1\end{pmatrix} the eigenvalue is 11, so you might expect nothing to grow. But Ak=(1k01)\mathbf{A}^k=\begin{pmatrix}1&k\\0&1\end{pmatrix}, and A10(1,1)=(11,1)\mathbf{A}^{10}(1,1)=(11,1): the length grows in proportion to kk. When there are too few eigenvectors (a defective matrix), the clean picture “each part is multiplied by its own λ\lambda” no longer describes everything.

Why this matters for deep learning. A deep network, or a recurrent network that reuses the same weight matrix W\mathbf{W} at every time step, multiplies by W\mathbf{W} over and over. In a simplified network with no nonlinearity, the signal after TT steps is WTh\mathbf{W}^T\mathbf{h}, and the gradient sent back through TT steps is multiplied by the transpose of W\mathbf{W} the same number of times, so over many steps its size follows the eigenvalues: if the spectral radius is above 11 the gradient tends to explode, and if it is below 11 it vanishes (for a non-symmetric W\mathbf{W} the size over a few steps can behave differently, as the shear showed). Real networks have activation functions, which change the details (P4.16 and P6.6 treat them), but the eigenvalue picture explains why the same matrix applied many times is dangerous, and why careful initialization (P4.12) aims to keep the scale near 11.

Go deeper Power iteration: finding the biggest eigenvalue by repeated multiplication

The swing you just saw is an algorithm. Start with any non-zero vector, multiply by A\mathbf{A}, divide by the length (so the numbers stay small), and repeat. The vector approaches the eigenvector of the largest ∣λ∣|\lambda|, and x⊤Ax\mathbf{x}^\top\mathbf{A}\mathbf{x} (for a unit vector x\mathbf{x} and a symmetric A\mathbf{A}) approaches that eigenvalue. This works when one eigenvalue has strictly the largest size and the start has some part along its eigenvector; the error shrinks by about the ratio ∣λ2∣/∣λ1∣|\lambda_2|/|\lambda_1| per step, here 13\tfrac13.

Try it: power iteration

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

You should see the vector approach (0.7071,0.7071)(0.7071,0.7071) and the estimate approach 33 (after step 1 the vector is (0.8944,0.4472)(0.8944,0.4472) and the estimate is 2.82.8). Power iteration is the idea behind computing a PageRank-style score and the top principal direction of large data sets when only a few eigenvectors are needed. (Practical libraries use more refined methods.)

Diagonalisation: eigenvectors as a new set of axes

Put the eigenvectors in the columns of a matrix V\mathbf{V}, and the eigenvalues on the diagonal of Λ\boldsymbol{\Lambda} (capital lambda). Since Avi=λivi\mathbf{A}\mathbf{v}_i=\lambda_i\mathbf{v}_i, multiplying A\mathbf{A} by V\mathbf{V} gives the columns λivi\lambda_i\mathbf{v}_i, which is the same as VΛ\mathbf{V}\boldsymbol{\Lambda} (the columns of V\mathbf{V} scaled, P1.B6):

AV=VΛ\mathbf{A}\mathbf{V}=\mathbf{V}\boldsymbol{\Lambda}

If V\mathbf{V} has an inverse, which needs nn independent eigenvectors, then

A=VΛV−1\mathbf{A}=\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1}

This is diagonalisation. For our matrix, V=(111−1)\mathbf{V}=\begin{pmatrix}1&1\\1&-1\end{pmatrix}, Λ=(3001)\boldsymbol{\Lambda}=\begin{pmatrix}3&0\\0&1\end{pmatrix} and V−1=12(111−1)\mathbf{V}^{-1}=\tfrac12\begin{pmatrix}1&1\\1&-1\end{pmatrix}, and multiplying out VΛV−1\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1} gives back (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix}.

Read it right to left, as in P1.B6: V−1\mathbf{V}^{-1} converts a vector into eigen-coordinates (how much of each eigenvector it contains, as in P1.B7), Λ\boldsymbol{\Lambda} stretches each coordinate by its own λ\lambda, and V\mathbf{V} converts back. In the eigen-coordinates the matrix is just a diagonal stretch, the simplest map there is.

That makes powers cheap, because the inner V−1V\mathbf{V}^{-1}\mathbf{V} pairs cancel:

Ak=VΛkV−1,Λk=(λ1k00λ2k)\begin{gathered} \mathbf{A}^k=\mathbf{V}\boldsymbol{\Lambda}^k\mathbf{V}^{-1}, \\ \boldsymbol{\Lambda}^k=\begin{pmatrix}\lambda_1^k&0\\0&\lambda_2^k\end{pmatrix} \end{gathered}

For k=10k=10: 310=590493^{10}=59049, so A10=12(59050590485904859050)=(29525295242952429525)\mathbf{A}^{10}=\tfrac12\begin{pmatrix}59050&59048\\59048&59050\end{pmatrix}=\begin{pmatrix}29525&29524\\29524&29525\end{pmatrix}, and you only had to raise two numbers to a power.

When can you diagonalise? When there are nn independent eigenvectors. That is certain if the nn eigenvalues are all different (different eigenvalues give independent eigenvectors). It can also happen with a repeated eigenvalue: 2I2\mathbf{I} is already diagonal. It fails for a defective matrix such as the shear: it has only the direction (1,0)(1,0), so there is no second independent eigenvector and V\mathbf{V} would have no inverse. For a rotation it fails with real numbers (it works with complex ones).

Symmetric matrices: the best-behaved case

P1.B10 promised this. A real matrix is symmetric if S⊤=S\mathbf{S}^\top=\mathbf{S} (P1.B10). The spectral theorem says that for a real symmetric n×nn\times n matrix:

  1. All the eigenvalues are real (no complex surprises).
  2. Eigenvectors for different eigenvalues are perpendicular.
  3. There is always a full set of nn perpendicular unit eigenvectors, even when an eigenvalue repeats.

Put those unit eigenvectors in the columns of Q\mathbf{Q}. They are orthonormal, so Q\mathbf{Q} is an orthogonal matrix and Q−1=Q⊤\mathbf{Q}^{-1}=\mathbf{Q}^\top (P1.B10), and diagonalisation becomes

S=QΛQ⊤\mathbf{S}=\mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top

with no inverse to compute. For (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix}, Q=12(111−1)\mathbf{Q}=\tfrac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix} and Λ=diag(3,1)\boldsymbol{\Lambda}=\mathrm{diag}(3,1). In words: a symmetric matrix stretches space along perpendicular directions and does nothing else. (A general matrix can also shear.)

The same fact written as a sum shows where P1.B11 comes in. With unit eigenvectors q1=12(1,1)\mathbf{q}_1=\tfrac{1}{\sqrt2}(1,1) and q2=12(1,−1)\mathbf{q}_2=\tfrac{1}{\sqrt2}(1,-1),

S=λ1q1q1⊤+λ2q2q2⊤=3⋅12(1111)+1⋅12(1−1−11)\begin{aligned} \mathbf{S}&=\lambda_1\mathbf{q}_1\mathbf{q}_1^\top+\lambda_2\mathbf{q}_2\mathbf{q}_2^\top\\ &=3\cdot\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix}+1\cdot\tfrac12\begin{pmatrix}1&-1\\-1&1\end{pmatrix} \end{aligned}

and each qiqi⊤\mathbf{q}_i\mathbf{q}_i^\top is the projection matrix onto the line of qi\mathbf{q}_i (P1.B11; the first one is the projection of the gallery). A symmetric matrix is a weighted sum of projections onto perpendicular directions, weighted by the eigenvalues. Compare the non-symmetric triangular matrix, whose eigenvectors (1,0)(1,0) and (1,1)(1,1) are not perpendicular, and the rotation, with no real eigenvectors at all.

Go deeper Why a symmetric matrix has perpendicular eigenvectors and real eigenvalues

Perpendicular. Let S\mathbf{S} be symmetric with Su=λu\mathbf{S}\mathbf{u}=\lambda\mathbf{u} and Sw=μw\mathbf{S}\mathbf{w}=\mu\mathbf{w}, where λ≠μ\lambda\ne\mu. P1.B10 showed that S\mathbf{S} can be moved across a dot product: (Su)⋅w=u⋅(Sw)(\mathbf{S}\mathbf{u})\cdot\mathbf{w}=\mathbf{u}\cdot(\mathbf{S}\mathbf{w}). So λ u⋅w=μ u⋅w\lambda\,\mathbf{u}\cdot\mathbf{w}=\mu\,\mathbf{u}\cdot\mathbf{w}, that is (λ−μ) u⋅w=0(\lambda-\mu)\,\mathbf{u}\cdot\mathbf{w}=0. Since λ≠μ\lambda\ne\mu, u⋅w=0\mathbf{u}\cdot\mathbf{w}=0.

Real, for 2×22\times2. For (abbd)\begin{pmatrix}a&b\\b&d\end{pmatrix} the number under the square root is (a−d)2+4b⋅b=(a−d)2+4b2≥0(a-d)^2+4b\cdot b=(a-d)^2+4b^2\ge0, so the square root is real and both eigenvalues are real. The proof for every size is a little longer and is left out here. The statement that there is always a full orthonormal set, even for a repeated eigenvalue, is also not proved here.

Positive definite matrices and the eigenvalue test

P1.B10 called a symmetric matrix positive semi-definite if x⊤Sx≥0\mathbf{x}^\top\mathbf{S}\mathbf{x}\ge0 for every x\mathbf{x}, and said that A⊤A\mathbf{A}^\top\mathbf{A} and covariance matrices always are. Eigenvalues give a clean test. For a real symmetric S\mathbf{S}:

  • Positive semi-definite   ⟺  \iff every eigenvalue is ≥0\ge0.
  • Positive definite (x⊤Sx>0\mathbf{x}^\top\mathbf{S}\mathbf{x}>0 for every non-zero x\mathbf{x})   ⟺  \iff every eigenvalue is >0>0.

The reason: for a unit eigenvector, q⊤Sq=λq⊤q=λ\mathbf{q}^\top\mathbf{S}\mathbf{q}=\lambda\mathbf{q}^\top\mathbf{q}=\lambda, so a negative eigenvalue gives a direction where x⊤Sx\mathbf{x}^\top\mathbf{S}\mathbf{x} is negative. Conversely, writing any x\mathbf{x} as c1q1+c2q2c_1\mathbf{q}_1+c_2\mathbf{q}_2 with the perpendicular unit eigenvectors, x⊤Sx=λ1c12+λ2c22\mathbf{x}^\top\mathbf{S}\mathbf{x}=\lambda_1c_1^2+\lambda_2c_2^2, which cannot be negative if both λ\lambda are ≥0\ge0.

This also explains why X⊤X\mathbf{X}^\top\mathbf{X} is positive semi-definite: for a unit eigenvector q\mathbf{q} with eigenvalue λ\lambda, λ=q⊤X⊤Xq=∥Xq∥2≥0\lambda=\mathbf{q}^\top\mathbf{X}^\top\mathbf{X}\mathbf{q}=\lVert\mathbf{X}\mathbf{q}\rVert^2\ge0. An eigenvalue 00 appears exactly when Xq=0\mathbf{X}\mathbf{q}=\mathbf{0}, a direction the data never uses.

Ridge regression (P1.B9’s promise). In P1.B9, a feature that was twice another gave X⊤X=(14282856)\mathbf{X}^\top\mathbf{X}=\begin{pmatrix}14&28\\28&56\end{pmatrix}, with trace 7070 and determinant 00, so its eigenvalues are 7070 and 00 (the direction (2,−1)(2,-1) is squashed). Ridge adds λI\lambda\mathbf{I} (here λ\lambda is the ridge strength, not an eigenvalue), and the rule from earlier says every eigenvalue goes up by λ\lambda, with the same eigenvectors. With ridge strength 11 the eigenvalues become 7171 and 11: none is 00, so the matrix (15282857)\begin{pmatrix}15&28\\28&57\end{pmatrix} is invertible (its determinant is 71⋅1=7171\cdot1=71, exactly what P1.B9 computed). In general, a positive semi-definite X⊤X\mathbf{X}^\top\mathbf{X} has eigenvalues μi≥0\mu_i\ge0, so X⊤X+λI\mathbf{X}^\top\mathbf{X}+\lambda\mathbf{I} has eigenvalues μi+λ≥λ>0\mu_i+\lambda\ge\lambda>0 for any ridge strength λ>0\lambda>0: it is always invertible. It also improves the ratio of largest to smallest eigenvalue, which is the condition number of a symmetric positive definite matrix (from infinite to 7171 here, a number P1.B13 explains).

Covariance and PCA (P3.C3). The covariance matrix Σ\boldsymbol{\Sigma} of a data set is symmetric and positive semi-definite. Take Σ=(2112)\boldsymbol{\Sigma}=\begin{pmatrix}2&1\\1&2\end{pmatrix}. The variance of the data along a unit direction u\mathbf{u} is u⊤Σu\mathbf{u}^\top\boldsymbol{\Sigma}\mathbf{u} (P1.B10, P1.D7). Along 12(1,1)\tfrac{1}{\sqrt2}(1,1) it is 33, and along 12(1,−1)\tfrac{1}{\sqrt2}(1,-1) it is 11: the eigenvalues. Over all unit directions, the variance is largest along the eigenvector of the largest eigenvalue, and the eigenvalues add up to the trace 44, the total variance. PCA is exactly this eigen-decomposition of the covariance matrix of the centred data, and P3.C3 builds on it.

Curvature (P1.C8). For a function of several variables, the Hessian matrix of second derivatives is symmetric, and its eigenvalues are the curvatures along its perpendicular eigen-directions: at a point where the gradient is zero (and no eigenvalue is 00), all positive means a bowl, all negative a hill, mixed signs a saddle.

Eigenvalues are not singular values

For a symmetric positive semi-definite matrix, the stretch factors of P1.B13 (singular values) are the eigenvalues. For other matrices, they are not. The shear (1101)\begin{pmatrix}1&1\\0&1\end{pmatrix} has eigenvalues 11 and 11, but it stretches the vector (1,1)(1,1) to (2,1)(2,1), and its largest stretch over all directions is 12(1+5)≈1.618\tfrac12(1+\sqrt5)\approx1.618, with the other stretch ≈0.618\approx0.618 (these are the singular values; their product is 1=∣det⁡∣1=|\det|). A rotation has complex eigenvalues but singular values 11 and 11. Eigenvalues only describe directions that stay on their own line, so they miss what a non-symmetric matrix does to other directions. Singular values describe the largest and smallest stretch over all directions, and they exist for non-square matrices too, which have no eigenvalues. P1.B13 develops them.

Try it in NumPy

np.linalg.eig(A) returns two things: an array of eigenvalues, and a matrix whose columns are the matching unit-length eigenvectors, so the eigenvector for vals[i] is vecs[:, i]. The order of the eigenvalues is not guaranteed, and the sign of each eigenvector is arbitrary. For a symmetric matrix use np.linalg.eigh: it is faster and more accurate, returns real numbers, sorts the eigenvalues from small to large, and gives perpendicular eigenvectors. It reads only one triangle of the matrix, so give it a matrix that really is symmetric: for any other matrix it silently returns wrong answers.

Try it: eig and eigh

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

What to expect:

  • The eigenvalues are 33 and 11, and A @ v equals lambda * v for both columns. The order, and the signs of the eigenvector columns, can differ on your machine (for example eig may list the eigenvalues as 3,13,1 or 1,31,3). The numbers 33 and 11 and the directions (1,1)/2(1,1)/\sqrt2 and (1,−1)/2(1,-1)/\sqrt2 do not change.
  • The trace equals the sum and the determinant equals the product of the eigenvalues.
  • eigh returns the eigenvalues in the order 1,31,3, and True for both checks: Q⊤Q=I\mathbf{Q}^\top\mathbf{Q}=\mathbf{I} and QΛQ⊤=A\mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top=\mathbf{A}.

The second cell runs the awkward cases of the gallery.

Try it: rotation and shear

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

  • For the rotation NumPy returns the complex pair ±i\pm i, printed like 0.+1.j and 0.-1.j (Python writes ii as j). The eigenvectors also have complex entries.
  • For the shear it returns 11 and 11, and two eigenvector columns that are almost the same direction: the second is (−1,about 2×10−16)(-1,\text{about }2\times10^{-16}), rounding noise. That is how a defective matrix shows up: the matrix of eigenvectors is (nearly) singular, so you cannot invert it to diagonalise. The exact tiny digits depend on the machine.
  • The projection gives 00 and 11 (eigvalsh is eigh without the vectors).

Where you will meet it next

  • PCA (P3.C3). The principal components are the eigenvectors of the covariance matrix, sorted by eigenvalue. The SVD of P1.B13 gives the same directions in a more stable way.
  • Exploding and vanishing gradients (P4.16, P6.6). A gradient that passes through the same weight matrix many times is scaled by powers of its eigenvalues, as in the power steps above. Gradient clipping and careful initialization (P4.12) try to keep the scale under control.
  • Learning rates and conditioning (P1.F3, P1.F5). The curvature of a loss in different directions is given by the eigenvalues of its Hessian (P1.C8). The box below connects this to the bowl x2+10y2x^2+10y^2 of P1.F3.
  • Ridge regression (P3.A6). Adding λI\lambda\mathbf{I} lifts every eigenvalue of X⊤X\mathbf{X}^\top\mathbf{X} by λ\lambda, as above.
  • Singular values and the SVD (P1.B13). For a general matrix, the eigen-ideas are replaced by singular values and two sets of perpendicular directions.
  • Markov chains. The long-run behaviour of a random walk on states is an eigenvector with eigenvalue 11 (see the box). PageRank, the original web-ranking idea, is a stationary distribution of this kind (a random-surfer Markov chain).
Go deeper Gradient descent is repeated multiplication by a matrix

P1.F3 ran gradient descent on f(x,y)=x2+10y2f(x,y)=x^2+10y^2. Its gradient is (2x,20y)(2x,20y), which equals H(xy)\mathbf{H}\begin{pmatrix}x\\y\end{pmatrix} for the diagonal matrix H=(20020)\mathbf{H}=\begin{pmatrix}2&0\\0&20\end{pmatrix} (the Hessian, P1.C8). So one step with learning rate η\eta is

(xy)←(xy)−ηH(xy)=(I−ηH)(xy)\begin{gathered} \begin{pmatrix}x\\y\end{pmatrix}\leftarrow\begin{pmatrix}x\\y\end{pmatrix}-\eta\mathbf{H}\begin{pmatrix}x\\y\end{pmatrix} \\ \quad=(\mathbf{I}-\eta\mathbf{H})\begin{pmatrix}x\\y\end{pmatrix} \end{gathered}

and the matrix I−ηH\mathbf{I}-\eta\mathbf{H} has eigenvalues 1−2η1-2\eta and 1−20η1-20\eta along the two axes, the factors of P1.F3. With η=0.095\eta=0.095 they are 0.810.81 and −0.9-0.9, exactly the numbers in that lesson: the yy-part flips sign and shrinks slowly, the xx-part shrinks smoothly. Gradient descent on this bowl converges when both ∣1−2η∣<1|1-2\eta|<1 and ∣1−20η∣<1|1-20\eta|<1, which means 0<η<220=0.10<\eta<\tfrac{2}{20}=0.1: at η=0.1\eta=0.1 the second factor is exactly −1-1 (bouncing forever), the “cap” that P1.F3 found. The steepest direction, the largest eigenvalue 2020, sets the cap; the shallowest, 22, sets the slow speed. The ratio of the largest to smallest eigenvalue, 20/2=1020/2=10, is the condition number of the bowl. The fastest choice for this bowl is η=220+2=111\eta=\tfrac{2}{20+2}=\tfrac1{11}, which makes both factors have size 911≈0.82\tfrac9{11}\approx0.82 (the larger the ratio, the closer to 11 this best speed is, and the slower the descent). This exact picture is for a quadratic bowl; for a general loss, the Hessian changes from place to place, but near a minimum the same reasoning applies.

Go deeper A Markov chain settles on an eigenvector

Suppose the weather is sunny or rainy. After a sunny day, tomorrow is sunny with probability 0.90.9; after a rainy day, tomorrow is sunny with probability 0.50.5. Put each row of probabilities in a matrix, so that each row adds to 11:

P=(0.90.10.50.5)\mathbf{P}=\begin{pmatrix}0.9&0.1\\0.5&0.5\end{pmatrix}

A row vector π\boldsymbol{\pi} of probabilities (sunny, rainy) becomes πP\boldsymbol{\pi}\mathbf{P} after one day. A distribution that does not change, πP=π\boldsymbol{\pi}\mathbf{P}=\boldsymbol{\pi}, is called stationary. Transposing, P⊤π⊤=π⊤\mathbf{P}^\top\boldsymbol{\pi}^\top=\boldsymbol{\pi}^\top: it is an eigenvector of P⊤\mathbf{P}^\top with eigenvalue 11. Here the trace is 1.41.4 and the determinant is 0.40.4, so the eigenvalues are 11 and 0.40.4, and the eigenvector for 11 is π=(56,16)\boldsymbol{\pi}=(\tfrac56,\tfrac16): check 0.9⋅56+0.5⋅16=560.9\cdot\tfrac56+0.5\cdot\tfrac16=\tfrac56. The other eigenvalue, 0.40.4, has size below 11, so as in the power steps its part fades like 0.4k0.4^k, and every starting distribution approaches (56,16)(\tfrac56,\tfrac16). (After 2020 days both rows of P20\mathbf{P}^{20} are about (0.833,0.167)(0.833,0.167).) For a larger chain the same idea holds under conditions (for example, that every state can eventually reach every other and that the chain does not cycle with a fixed period) that a probability course explains.

Common mistakes

Check your understanding

  1. Let A=(2112)\mathbf{A}=\begin{pmatrix}2&1\\1&2\end{pmatrix}. Which of these is an eigenvector of A\mathbf{A}?

  2. A real 2×22\times2 matrix has trace 55 and determinant 66. What are its eigenvalues?

  3. A real 2×22\times2 matrix has an eigenvalue 00. Which statement must be true?

  4. S\mathbf{S} is a real symmetric matrix, and u\mathbf{u} and w\mathbf{w} are eigenvectors of S\mathbf{S} with different eigenvalues. What is true of u\mathbf{u} and w\mathbf{w}?

  5. A real diagonalisable 2×22\times2 matrix has eigenvalues 1.21.2 and 0.50.5. A vector x\mathbf{x} has a non-zero part along both eigen-directions. What happens to Akx\mathbf{A}^k\mathbf{x} as kk grows large?

  6. Which real 2×22\times2 matrix has exactly one eigen-direction?

  7. S\mathbf{S} is a real symmetric matrix with eigenvalues 33 and −1-1. Is it positive semi-definite?

Exercises

  1. Find the eigenvalues and eigenvectors of (4123)\begin{pmatrix}4&1\\2&3\end{pmatrix} and check one of them.
    Show answerTrace 77, det⁡=12−2=10\det=12-2=10, so λ2−7λ+10=0\lambda^2-7\lambda+10=0 and λ=5\lambda=5 or λ=2\lambda=2. For 55: (−112−2)v=0\begin{pmatrix}-1&1\\2&-2\end{pmatrix}\mathbf{v}=\mathbf{0} gives y=xy=x, so v=(1,1)\mathbf{v}=(1,1); check A(1,1)=(5,5)\mathbf{A}(1,1)=(5,5). For 22: (2121)v=0\begin{pmatrix}2&1\\2&1\end{pmatrix}\mathbf{v}=\mathbf{0} gives y=−2xy=-2x, so v=(1,−2)\mathbf{v}=(1,-2); check A(1,−2)=(2,−4)=2 (1,−2)\mathbf{A}(1,-2)=(2,-4)=2\,(1,-2).
  2. Without solving anything, give the eigenvalues of (305−2)\begin{pmatrix}3&0\\5&-2\end{pmatrix}, then find the eigenvectors.
    Show answerIt is triangular, so the eigenvalues are the diagonal entries 33 and −2-2. For 33: (005−5)v=0\begin{pmatrix}0&0\\5&-5\end{pmatrix}\mathbf{v}=\mathbf{0} gives x=yx=y, so (1,1)(1,1) (check: A(1,1)=(3,3)\mathbf{A}(1,1)=(3,3)). For −2-2: (5050)v=0\begin{pmatrix}5&0\\5&0\end{pmatrix}\mathbf{v}=\mathbf{0} gives x=0x=0, so (0,1)(0,1) (check: A(0,1)=(0,−2)\mathbf{A}(0,1)=(0,-2)).
  3. A 2×22\times2 matrix has eigenvalues 55 and −1-1. Give its trace and determinant, and the eigenvalues of A2\mathbf{A}^2, A−1\mathbf{A}^{-1} and A+3I\mathbf{A}+3\mathbf{I}.
    Show answerTrace =5+(−1)=4=5+(-1)=4 and det⁡=5⋅(−1)=−5\det=5\cdot(-1)=-5. A2\mathbf{A}^2 has 2525 and 11. A−1\mathbf{A}^{-1} exists since 00 is not an eigenvalue, and has 15\tfrac15 and −1-1. A+3I\mathbf{A}+3\mathbf{I} has 88 and 22.
  4. Find the eigenvalues and eigenvectors of (2412)\begin{pmatrix}2&4\\1&2\end{pmatrix} and say what the eigenvalue 00 means.
    Show answerTrace 44, det⁡=0\det=0, so λ=4\lambda=4 or 00. For 44: (−241−2)v=0\begin{pmatrix}-2&4\\1&-2\end{pmatrix}\mathbf{v}=\mathbf{0} gives x=2yx=2y, so (2,1)(2,1); check A(2,1)=(8,4)=4 (2,1)\mathbf{A}(2,1)=(8,4)=4\,(2,1). For 00: Av=0\mathbf{A}\mathbf{v}=\mathbf{0} gives (2,−1)(2,-1); check A(2,−1)=(0,0)\mathbf{A}(2,-1)=(0,0). The eigenvalue 00 means the line through (2,−1)(2,-1) is squashed to the origin: det⁡=0\det=0, the rank is 11 and there is no inverse.
  5. Show that (1−111)\begin{pmatrix}1&-1\\1&1\end{pmatrix} has no real eigen-directions. What does it do to the plane?
    Show answerTrace 22, det⁡=2\det=2, so λ2−2λ+2=0\lambda^2-2\lambda+2=0 and the number under the root is 4−8=−4<04-8=-4<0: no real solution. (The eigenvalues are 1±i1\pm i.) The matrix is a 45∘45^\circ rotation combined with a stretch by 2\sqrt2, so it turns every direction.
  6. For which values of cc does (1c01)\begin{pmatrix}1&c\\0&1\end{pmatrix} have more than one eigen-direction?
    Show answerThe eigenvalue is 11 twice, and (0c00)v=0\begin{pmatrix}0&c\\0&0\end{pmatrix}\mathbf{v}=\mathbf{0} forces y=0y=0 when c≠0c\ne0: only the direction (1,0)(1,0). For c=0c=0 the matrix is I\mathbf{I} and every direction works. So only c=0c=0.
  7. Diagonalise S=(3113)\mathbf{S}=\begin{pmatrix}3&1\\1&3\end{pmatrix} as QΛQ⊤\mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top and use it to find S5\mathbf{S}^5.
    Show answerTrace 66, det⁡=8\det=8, so λ=4\lambda=4 and 22, with unit eigenvectors 12(1,1)\tfrac1{\sqrt2}(1,1) and 12(1,−1)\tfrac1{\sqrt2}(1,-1). Then S5=Q diag(45,25) Q⊤=12(1024+321024−321024−321024+32)=(528496496528)\mathbf{S}^5=\mathbf{Q}\,\mathrm{diag}(4^5,2^5)\,\mathbf{Q}^\top=\tfrac12\begin{pmatrix}1024+32&1024-32\\1024-32&1024+32\end{pmatrix}=\begin{pmatrix}528&496\\496&528\end{pmatrix}.
  8. Decide whether each symmetric matrix is positive semi-definite: (2−1−12)\begin{pmatrix}2&-1\\-1&2\end{pmatrix} and (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix}.
    Show answerThe first has trace 44 and det⁡=3\det=3, so eigenvalues 33 and 11, both positive: positive definite. The second has trace 22 and det⁡=−3\det=-3, so eigenvalues 33 and −1-1: not positive semi-definite. For example x=(1,−1)\mathbf{x}=(1,-1) gives x⊤Sx=1−2−2+1=−2<0\mathbf{x}^\top\mathbf{S}\mathbf{x}=1-2-2+1=-2<0.
  9. Gradient descent on f(x,y)=x2+10y2f(x,y)=x^2+10y^2 (Hessian eigenvalues 22 and 2020) uses η=0.05\eta=0.05, then η=0.11\eta=0.11. What are the per-step factors on the xx and yy parts, and what happens?
    Show answerThe factors are 1−2η1-2\eta and 1−20η1-20\eta. At η=0.05\eta=0.05: 0.90.9 and 00, so yy becomes exactly 00 after one step and xx shrinks by 10%10\% per step: it converges. At η=0.11\eta=0.11: 0.780.78 and −1.2-1.2. Since ∣−1.2∣>1|-1.2|>1, the yy part flips sign and grows by 20%20\% per step: it diverges.
  10. A matrix has eigenvalues 1.11.1 and 0.90.9. For a vector with parts along both, by what factor has the first part grown compared with the second after 5050 steps? How many steps double the ratio?
    Show answerThe ratio of the two parts is multiplied by 1.1/0.9≈1.2221.1/0.9\approx1.222 per step, so after 5050 steps it has grown by (1.1/0.9)50≈2.3×104(1.1/0.9)^{50}\approx2.3\times10^4 (separately, 1.150≈117.41.1^{50}\approx117.4 and 0.950≈0.00520.9^{50}\approx0.0052). Doubling the ratio takes about ln⁡2/ln⁡(1.1/0.9)≈3.5\ln2/\ln(1.1/0.9)\approx3.5 steps.
  11. Explain why a square matrix with a non-zero vector v\mathbf{v} in its null space has the eigenvalue 00.
    Show answerAv=0=0⋅v\mathbf{A}\mathbf{v}=\mathbf{0}=0\cdot\mathbf{v} with v≠0\mathbf{v}\ne\mathbf{0}, which is the definition with λ=0\lambda=0. By P1.B7, a square matrix has a non-zero null vector exactly when its columns are dependent, that is when det⁡=0\det=0.
  12. Code: predict, then check with np.linalg.eig, the eigenvalues of (01−10)\begin{pmatrix}0&1\\-1&0\end{pmatrix}.
    Show answerTrace 00, det⁡=1\det=1, so λ2+1=0\lambda^2+1=0 and λ=±i\lambda=\pm i. NumPy prints the complex pair 0.+1.j and 0.-1.j (the order may differ). It is a quarter turn in the other direction, so no real eigen-direction exists.

Key takeaways

  • An eigenvector of a square matrix A\mathbf{A} is a non-zero vector that A\mathbf{A} only stretches, shrinks or flips: Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v}. The number λ\lambda is its eigenvalue. The zero vector is excluded (it satisfies the equation for every λ\lambda), but λ=0\lambda=0 is allowed.
  • Any non-zero multiple of an eigenvector is an eigenvector with the same λ\lambda, so an eigenvector is really a direction (a line through the origin). λ=0\lambda=0 means that line is squashed to the origin: it is the null space, and det⁡=0\det=0.
  • For 2×22\times2: solve λ2−(trace)λ+det⁡=0\lambda^2-(\text{trace})\lambda+\det=0 for λ\lambda, then solve (A−λI)v=0(\mathbf{A}-\lambda\mathbf{I})\mathbf{v}=\mathbf{0} for v\mathbf{v}. The eigenvalues add up to the trace and multiply to the determinant. For a triangular matrix they are the diagonal entries.
  • A real 2×22\times2 matrix has two real eigen-directions, or one (a shear: repeated and defective), or every direction (a multiple of I\mathbf{I}), or none (a rotation: complex eigenvalues). A projection has eigenvalues 11 and 00, a reflection 11 and −1-1.
  • Akv=λkv\mathbf{A}^k\mathbf{v}=\lambda^k\mathbf{v}, so for a typical x\mathbf{x} the eigen-direction with the largest ∣λ∣|\lambda| takes over and the length grows by about ∣λ∣|\lambda| per step if ∣λ∣>1|\lambda|>1 and shrinks if ∣λ∣<1|\lambda|<1. This is behind exploding and vanishing gradients and the speed of gradient descent. With nn independent eigenvectors, A=VΛV−1\mathbf{A}=\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1} and Ak=VΛkV−1\mathbf{A}^k=\mathbf{V}\boldsymbol{\Lambda}^k\mathbf{V}^{-1}.
  • A real symmetric matrix has real eigenvalues and perpendicular eigenvectors, so S=QΛQ⊤\mathbf{S}=\mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top (the spectral theorem). It is positive semi-definite exactly when every eigenvalue is at least 00, which holds for X⊤X\mathbf{X}^\top\mathbf{X} and for covariance matrices.
  • Eigenvalues are not singular values: they agree for symmetric positive semi-definite matrices but can differ a lot otherwise. A shear has eigenvalues 1,11,1 and still stretches some vectors by about 1.621.62 (P1.B13).
Found a mistake? Tell us