What symmetry guarantees
The matrix of lesson 3.6.1 has eigenvectors and , at an angle of 101.31° (lesson 3.1.2). The symmetric matrix has eigenvectors and , at exactly 90°. That is no accident.
Rule: Symmetric matrices
Let be a symmetric matrix with real entries (lesson 3.2.3). Its eigenvalues, counted with repeats, are all real. Eigenvectors of different eigenvalues are perpendicular, and always has eigenvectors that are perpendicular to each other, even when an eigenvalue repeats.
This is stated here without proof. For a symmetric matrix , the reality of the eigenvalues shows in the discriminant of lesson 3.6.1:
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 and , that is, for a multiple of .
A example. Take
It sends to , to and to . So its eigenvalues are 6, 3 and 2, and the three eigenvectors have dot products , and : each pair is perpendicular.
Try it
angle is lesson 3.1.2's formula, in degrees. The loop multiplies by its three eigenvectors; then the three dot products.
The last line evaluates both sides of the discriminant identity for , with , , .
The orthogonal matrix Q
Scale each eigenvector to length 1. For that gives
The letter 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 . Entry of is : 1 when , and 0 otherwise. So .
Rule: An orthogonal matrix
A square matrix with orthonormal columns is called orthogonal. Its inverse is its transpose, so there is nothing to compute, and 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 . For a symmetric matrix, take ; then is simply .
Rule: The spectral theorem
Every symmetric matrix factors this way. is orthogonal, with orthonormal eigenvectors as its columns, and holds the real eigenvalues in the same order. The set of eigenvalues is called the spectrum of , hence the name.
Read the product from right to left. : the coordinates of along the eigenvectors are plain dot products. multiplies each coordinate by its eigenvalue, and builds the vector back.
For and :
| step | result |
|---|---|
| , the coordinates | |
| times | |
| times , back to the plane |
That is , the first column of doubled.
Try it
The cell builds from the two unit eigenvectors and checks and .
The last line follows through the three steps, then prints for comparison.
The picture: a circle becomes an ellipse
Each unit vector is a point of the unit circle (lesson 1.7.1). keeps lengths, so it moves the circle onto itself. then stretches it by along one axis and by along the other, and turns those axes onto and .
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 and .
stretches the unit circle by 3 along and by 1 along : an ellipse whose axes are the perpendicular eigenvectors. Every other unit vector, such as , lands somewhere between.
No unit vector is stretched more than or less than . Checking 720 points round the circle, the images of have lengths between exactly 1 and 3, reached along and .
A negative eigenvalue flips one axis but gives the same ellipse. has the same eigenvectors as , with eigenvalues 3 and : it sends to .
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 and prints the longest and shortest images. Then and .
The last line is : , and .
A sum of projections
Multiply out one column of at a time: each eigenvector contributes its own piece.
Rule: The spectral decomposition
Each , a column times a row, is the matrix that projects onto the line through (lesson 3.5.2). An symmetric matrix is a sum of such pieces.
For , the two pieces are
and .
So : project onto each eigenvector line, scale by the eigenvalue, and add. For the first projection is , so the first piece gives and the second : together .
The same holds for , with three pieces. Dropping the pieces with the smallest eigenvalues leaves a simpler matrix that still does most of what 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 . The cell rebuilds from its two pieces, checks that for the first (a projection, lesson 3.5.2), and projects with it.
The last line rebuilds from its three pieces. Each is for the unit vector .
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 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.
eigguarantees 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 it gives 6, 3 and 2, with the unit eigenvectors , and .
The rule of lesson 3.6.1 for matrices checks out. The eigenvalues of add up to , its trace , 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 , and gives back the whole-number eigenvectors.
The last line compares the sum and product of the eigenvalues with the trace and the determinant.
A repeated eigenvalue
has eigenvalues 4, 1 and 1. The eigenvector of 4 is . For the eigenvalue 1, every vector perpendicular to works, such as or : 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 , 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 , it returns 1 and 3, the eigenvalues of . The true eigenvalues of are 4.2361 and .
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 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
's eigenvalues, with despite the repeat, and two of its eigenvectors for .
Then eigh on the non-symmetric , against eig, and the symmetry test that would have caught it. The last line is of case study 3.2.5.
Common mistakes
- Perpendicular eigenvectors need symmetry. has eigenvectors at 101.31°.
- Normalise before you build . With and as columns, , and is not the inverse.
eighlists the eigenvalues in increasing order. The largest is last; reverse both the values and the columns.eighreads only one triangle. Checknp.allclose(A, A.T)before you trust it.- The semi-axes are . A negative eigenvalue flips its axis but does not shrink the ellipse.
- 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.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 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,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for 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 orthonormal ones, even with a repeated eigenvalue (stated without proof).
- Unit eigenvectors as columns make an orthogonal matrix: , so . It keeps lengths and angles.
- The spectral theorem: . gives the coordinates along the eigenvectors, scales them, builds the vector back.
- A symmetric matrix maps the unit circle to an ellipse along its eigenvectors, with semi-axes and .
- , 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.