SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 3.6.1 Eigenvalues and eigenvectorsConcept · 35 min
      2. 3.6.2 Diagonalisation and matrix powersConcept · 30 min
      3. 3.6.3 Symmetric matrices and the spectral theoremConcept · 30 min
      4. 3.6.4 Practice set: eigenvaluesPractice set · 20 min
      5. 3.6.5 Case study: principal components of the yield curveCase study · 35 min

Level 3, Linear algebra 3.6 Eigenvalues and eigenvectors Lesson 3 of 5

ConceptLesson 3.6.3 in Level 3, Linear algebra. About 30 minutes.

Symmetric matrices and the spectral theorem

What symmetry guarantees

The matrix A=(1232)A = \begin{pmatrix} 1 & 2 \\ 3 & 2 \end{pmatrix} of lesson 3.6.1 has eigenvectors (2,3)(2, 3) and (1,−1)(1, -1), at an angle of 101.31° (lesson 3.1.2). The symmetric matrix S=(2112)S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} has eigenvectors (1,1)(1, 1) and (1,−1)(1, -1), at exactly 90°. That is no accident.

Rule: Symmetric matrices

A⊤=A  ⟹  λ real, qi⊥qjA^\top = A \implies \lambda \text{ real}, \ \mathbf{q}_i \perp \mathbf{q}_j

Let AA be a symmetric n×nn \times n matrix with real entries (lesson 3.2.3). Its nn eigenvalues, counted with repeats, are all real. Eigenvectors of different eigenvalues are perpendicular, and AA always has nn eigenvectors that are perpendicular to each other, even when an eigenvalue repeats.

This is stated here without proof. For a 2×22 \times 2 symmetric matrix (abbd)\begin{pmatrix} a & b \\ b & d \end{pmatrix}, the reality of the eigenvalues shows in the discriminant of lesson 3.6.1:

(a+d)2−4(ad−b2)=(a−d)2+4b2\begin{gathered} (a + d)^2 - 4(ad - b^2) \\ = (a - d)^2 + 4b^2 \end{gathered}

A sum of squares is never negative, so the eigenvalues are never complex. A symmetric matrix cannot turn the plane the way a rotation does. The discriminant is 0 only when a=da = d and b=0b = 0, that is, for a multiple of II.

A 3×33 \times 3 example. Take

B=(3−11−15−11−13)B = \begin{pmatrix} 3 & -1 & 1 \\ -1 & 5 & -1 \\ 1 & -1 & 3 \end{pmatrix}

It sends (1,−2,1)(1, -2, 1) to (6,−12,6)(6, -12, 6), (1,1,1)(1, 1, 1) to (3,3,3)(3, 3, 3) and (1,0,−1)(1, 0, -1) to (2,0,−2)(2, 0, -2). So its eigenvalues are 6, 3 and 2, and the three eigenvectors have dot products 1−2+1=01 - 2 + 1 = 0, 1+0−1=01 + 0 - 1 = 0 and 1+0−1=01 + 0 - 1 = 0: each pair is perpendicular.

Try it

angle is lesson 3.1.2's formula, in degrees. The loop multiplies BB by its three eigenvectors; then the three dot products.

The last line evaluates both sides of the discriminant identity for SS, with a=2a = 2, b=1b = 1, d=2d = 2.

⌘/Ctrl + Enter runs the cell

The orthogonal matrix Q

Scale each eigenvector to length 1. For SS that gives

q1=12(1,1)≈(0.7071,0.7071)q2=12(1,−1)≈(0.7071,−0.7071)\begin{gathered} \mathbf{q}_1 = \tfrac{1}{\sqrt{2}}(1, 1) \approx (0.7071, 0.7071) \\[4pt] \mathbf{q}_2 = \tfrac{1}{\sqrt{2}}(1, -1) \approx (0.7071, -0.7071) \end{gathered}

The letter q\mathbf{q} marks an eigenvector of length 1. These two are perpendicular and of length 1: they are orthonormal, as in lesson 3.5.2.

Put them side by side as the columns of QQ. Entry (i,j)(i, j) of Q⊤QQ^\top Q is qi⋅qj\mathbf{q}_i \cdot \mathbf{q}_j: 1 when i=ji = j, and 0 otherwise. So Q⊤Q=IQ^\top Q = I.

Rule: An orthogonal matrix

Q⊤Q=IQ−1=Q⊤\begin{gathered} Q^\top Q = I \\[4pt] Q^{-1} = Q^\top \end{gathered}

A square matrix with orthonormal columns is called orthogonal. Its inverse is its transpose, so there is nothing to compute, and QQ⊤=IQQ^\top = I as well. As a map it keeps every length and angle: it is a rotation or a reflection (lesson 3.2.2).

The spectral theorem

Lesson 3.6.2 wrote a diagonalisable matrix as PΛP−1P\Lambda P^{-1}. For a symmetric matrix, take P=QP = Q; then P−1P^{-1} is simply Q⊤Q^\top.

Rule: The spectral theorem

A=QΛQ⊤A = Q\Lambda Q^\top

Every symmetric matrix factors this way. QQ is orthogonal, with orthonormal eigenvectors as its columns, and Λ\Lambda holds the real eigenvalues in the same order. The set of eigenvalues is called the spectrum of AA, hence the name.

Read the product from right to left. Q⊤x=(q1⋅x, q2⋅x)Q^\top\mathbf{x} = (\mathbf{q}_1 \cdot \mathbf{x},\ \mathbf{q}_2 \cdot \mathbf{x}): the coordinates of x\mathbf{x} along the eigenvectors are plain dot products. Λ\Lambda multiplies each coordinate by its eigenvalue, and QQ builds the vector back.

For SS and x=(2,0)\mathbf{x} = (2, 0):

stepresult
Q⊤xQ^\top\mathbf{x}, the coordinates(1.4142,1.4142)(1.4142, 1.4142)
times Λ=(3001)\Lambda = \begin{pmatrix} 3 & 0 \\ 0 & 1 \end{pmatrix}(4.2426,1.4142)(4.2426, 1.4142)
times QQ, back to the plane(4,2)(4, 2)

That is S(2,0)=(4,2)S(2, 0) = (4, 2), the first column of SS doubled.

Try it

The cell builds QQ from the two unit eigenvectors and checks Q⊤Q=IQ^\top Q = I and QΛQ⊤=SQ\Lambda Q^\top = S.

The last line follows x=(2,0)\mathbf{x} = (2, 0) through the three steps, then prints SxS\mathbf{x} for comparison.

⌘/Ctrl + Enter runs the cell

The picture: a circle becomes an ellipse

Each unit vector (cos⁡t,sin⁡t)(\cos t, \sin t) is a point of the unit circle (lesson 1.7.1). Q⊤Q^\top keeps lengths, so it moves the circle onto itself. Λ\Lambda then stretches it by λ1\lambda_1 along one axis and by λ2\lambda_2 along the other, and QQ turns those axes onto q1\mathbf{q}_1 and q2\mathbf{q}_2.

So a symmetric matrix maps the unit circle to an ellipse whose axes point along its eigenvectors. The half-lengths of the axes, the semi-axes, are ∣λ1∣\lvert\lambda_1\rvert and ∣λ2∣\lvert\lambda_2\rvert.

SS stretches the unit circle by 3 along q1\mathbf{q}_1 and by 1 along q2\mathbf{q}_2: an ellipse whose axes are the perpendicular eigenvectors. Every other unit vector, such as (1,0)(1, 0), lands somewhere between.

No unit vector is stretched more than ∣λ1∣\lvert\lambda_1\rvert or less than ∣λ2∣\lvert\lambda_2\rvert. Checking 720 points round the circle, the images of SS have lengths between exactly 1 and 3, reached along q2\mathbf{q}_2 and q1\mathbf{q}_1.

A negative eigenvalue flips one axis but gives the same ellipse. N=(1221)N = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} has the same eigenvectors as SS, with eigenvalues 3 and −1-1: it sends q2\mathbf{q}_2 to −q2-\mathbf{q}_2.

A matrix that is not symmetric also maps the circle to an ellipse, but the axes of that ellipse are not its eigenvectors. Lesson 3.8.1 finds them with the singular value decomposition.

Try it

The cell maps 721 points of the unit circle by SS and prints the longest and shortest images. Then Sq1=3q1S\mathbf{q}_1 = 3\mathbf{q}_1 and Sq2=q2S\mathbf{q}_2 = \mathbf{q}_2.

The last line is NN: Nq1=3q1N\mathbf{q}_1 = 3\mathbf{q}_1, and Nq2=−q2N\mathbf{q}_2 = -\mathbf{q}_2.

⌘/Ctrl + Enter runs the cell

A sum of projections

Multiply out QΛQ⊤Q\Lambda Q^\top one column of QQ at a time: each eigenvector contributes its own piece.

Rule: The spectral decomposition

A=λ1q1q1⊤+λ2q2q2⊤A = \lambda_1\mathbf{q}_1\mathbf{q}_1^\top + \lambda_2\mathbf{q}_2\mathbf{q}_2^\top

Each qq⊤\mathbf{q}\mathbf{q}^\top, a column times a row, is the matrix that projects onto the line through q\mathbf{q} (lesson 3.5.2). An n×nn \times n symmetric matrix is a sum of nn such pieces.

For SS, the two pieces are

q1q1⊤=(0.50.50.50.5)q2q2⊤=(0.5−0.5−0.50.5)\begin{gathered} \mathbf{q}_1\mathbf{q}_1^\top = \begin{pmatrix} 0.5 & 0.5 \\ 0.5 & 0.5 \end{pmatrix} \\[6pt] \mathbf{q}_2\mathbf{q}_2^\top = \begin{pmatrix} 0.5 & -0.5 \\ -0.5 & 0.5 \end{pmatrix} \end{gathered}

and 3 q1q1⊤+1 q2q2⊤=(2112)=S3\,\mathbf{q}_1\mathbf{q}_1^\top + 1\,\mathbf{q}_2\mathbf{q}_2^\top = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} = S.

So Ax=λ1(q1⋅x) q1+λ2(q2⋅x) q2A\mathbf{x} = \lambda_1(\mathbf{q}_1 \cdot \mathbf{x})\,\mathbf{q}_1 + \lambda_2(\mathbf{q}_2 \cdot \mathbf{x})\,\mathbf{q}_2: project x\mathbf{x} onto each eigenvector line, scale by the eigenvalue, and add. For x=(2,0)\mathbf{x} = (2, 0) the first projection is (1,1)(1, 1), so the first piece gives (3,3)(3, 3) and the second (1,−1)(1, -1): together (4,2)(4, 2).

The same holds for BB, with three pieces. Dropping the pieces with the smallest eigenvalues leaves a simpler matrix that still does most of what AA does. Case study 3.6.5 does this with a covariance matrix, and lesson 3.8.2 does it for any matrix.

Try it

np.outer(q, q) is qq⊤\mathbf{q}\mathbf{q}^\top. The cell rebuilds SS from its two pieces, checks that P2=PP^2 = P for the first (a projection, lesson 3.5.2), and projects (2,0)(2, 0) with it.

The last line rebuilds BB from its three pieces. Each vv⊤v⋅v\frac{\mathbf{v}\mathbf{v}^\top}{\mathbf{v} \cdot \mathbf{v}} is qq⊤\mathbf{q}\mathbf{q}^\top for the unit vector q=v/∥v∥\mathbf{q} = \mathbf{v}/\lVert\mathbf{v}\rVert.

⌘/Ctrl + Enter runs the cell

eigh: eigenvalues of a symmetric matrix

np.linalg.eigh(A) is made for symmetric matrices. It returns the eigenvalues as real numbers in increasing order, and a matrix QQ whose columns are orthonormal eigenvectors.

Prefer it to eig whenever the matrix is symmetric:

  • It keeps the promises of this lesson. The eigenvalues are always real and the columns always orthonormal, even when an eigenvalue repeats. eig guarantees neither.
  • It is faster and more accurate, because it uses the symmetry.

Reverse its output to put the largest eigenvalue first, and fix the signs as in lesson 3.6.1. For BB it gives 6, 3 and 2, with the unit eigenvectors (1,−2,1)/6(1, -2, 1)/\sqrt{6}, (1,1,1)/3(1, 1, 1)/\sqrt{3} and (1,0,−1)/2(1, 0, -1)/\sqrt{2}.

The rule of lesson 3.6.1 for n×nn \times n matrices checks out. The eigenvalues of BB add up to 6+3+2=116 + 3 + 2 = 11, its trace 3+5+33 + 5 + 3, and multiply to 36, its determinant.

Try it

The first line is eigh's own order. After reversing and fixing signs, multiplying each column by 6\sqrt{6}, 3\sqrt{3} and 2\sqrt{2} gives back the whole-number eigenvectors.

The last line compares the sum and product of the eigenvalues with the trace and the determinant.

⌘/Ctrl + Enter runs the cell

A repeated eigenvalue

J=(211121112)J = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix} has eigenvalues 4, 1 and 1. The eigenvector of 4 is (1,1,1)(1, 1, 1). For the eigenvalue 1, every vector perpendicular to (1,1,1)(1, 1, 1) works, such as (1,−1,0)(1, -1, 0) or (1,1,−2)(1, 1, -2): a whole plane of eigenvectors.

eigh picks two perpendicular unit vectors in that plane. Which two it picks can differ between computers, so compare the eigenvalues and Q⊤Q=IQ^\top Q = I, not the columns themselves.

The trap: eigh trusts you

eigh assumes the matrix is symmetric and reads only the entries on and below the diagonal. Given T=(2512)T = \begin{pmatrix} 2 & 5 \\ 1 & 2 \end{pmatrix}, it returns 1 and 3, the eigenvalues of (2112)\begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}. The true eigenvalues of TT are 4.2361 and −0.2361-0.2361.

So check symmetry first with np.allclose(A, A.T), as case study 3.2.5 did for a covariance matrix.

Covariance matrices

The covariance matrix Σ\Sigma of case study 3.2.5 is symmetric, so all of this applies to it: real eigenvalues and perpendicular eigenvectors. Its eigenvalues are 0.0751, 0.0225 and 0.0117, and they add up to its trace, 0.1093, the sum of the three variances.

Case study 3.6.5 reads such eigenvalues as the variance along each eigenvector. Module 3.7 uses their signs to tell which symmetric matrices can be covariance matrices at all, starting with quadratic forms in lesson 3.7.1.

Try it

JJ's eigenvalues, with Q⊤Q=IQ^\top Q = I despite the repeat, and two of its eigenvectors for λ=1\lambda = 1.

Then eigh on the non-symmetric TT, against eig, and the symmetry test that would have caught it. The last line is Σ\Sigma of case study 3.2.5.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. Perpendicular eigenvectors need symmetry. A=(1232)A = \begin{pmatrix} 1 & 2 \\ 3 & 2 \end{pmatrix} has eigenvectors at 101.31°.
  2. Normalise before you build QQ. With (1,1)(1, 1) and (1,−1)(1, -1) as columns, Q⊤Q=2IQ^\top Q = 2I, and Q⊤Q^\top is not the inverse.
  3. eigh lists the eigenvalues in increasing order. The largest is last; reverse both the values and the columns.
  4. eigh reads only one triangle. Check np.allclose(A, A.T) before you trust it.
  5. The semi-axes are ∣λ∣\lvert\lambda\rvert. A negative eigenvalue flips its axis but does not shrink the ellipse.
  6. A repeated eigenvalue gives a whole plane of eigenvectors. Any perpendicular pair in it is correct, so do not compare those columns between computers.

Symmetric matrices and the spectral theorem

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A real symmetric matrix has real eigenvalues and perpendicular eigenvectors, and always nn orthonormal ones, even with a repeated eigenvalue (stated without proof).
  • Unit eigenvectors as columns make an orthogonal matrix: Q⊤Q=IQ^\top Q = I, so Q−1=Q⊤Q^{-1} = Q^\top. It keeps lengths and angles.
  • The spectral theorem: A=QΛQ⊤A = Q\Lambda Q^\top. Q⊤xQ^\top\mathbf{x} gives the coordinates along the eigenvectors, Λ\Lambda scales them, QQ builds the vector back.
  • A symmetric matrix maps the unit circle to an ellipse along its eigenvectors, with semi-axes ∣λ1∣\lvert\lambda_1\rvert and ∣λ2∣\lvert\lambda_2\rvert.
  • A=∑iλiqiqi⊤A = \sum_i \lambda_i\mathbf{q}_i\mathbf{q}_i^\top, a sum of projections onto the eigenvector lines.
  • np.linalg.eigh: real eigenvalues in increasing order, orthonormal columns. Reverse for largest first, fix signs, and check symmetry first, because it reads only one triangle.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.