Lecture 10: The Spectral Theorem and the Singular Value Decomposition
These notes are interactive: click a section title to open it, click any dotted term to unfold its exact definition or statement in place, click ▸ Proof to expand a proof, and try the exercises — answers are checked instantly.
10.1 Symmetric matrices, the spectral theorem, and quadratic forms
Lecture 8 met two obstacles to diagonalizing a matrix: eigenvalues that are not real, and eigenspaces that are too small. For a symmetric matrix neither happens, and more is true: the eigenvectors can be chosen orthonormal, so that with an orthogonal matrix. This is the spectral theorem. Geometrically, a symmetric matrix stretches space along mutually perpendicular directions, by the factors . The same directions answer an optimization question: on the unit sphere, the quadratic form is largest in the direction of an eigenvector for the largest eigenvalue and smallest in the direction of one for the smallest. In Section 10.2 this is applied to the symmetric matrix of an arbitrary matrix , which produces the singular value decomposition.
A square matrix is symmetric if , that is, for all : the entries are mirrored across the diagonal.
- For every matrix , the matrices () and () are symmetric: by the transpose rule (Theorem 4.17), , and likewise for . By Lemma 9.15, the entries of are the inner products of the columns of .
- The matrix of an orthogonal projection is symmetric (part (f) of Theorem 9.34).
- The matrices and are symmetric; the rotation of Example 8.26, which has no real eigenvalue, is not.
An matrix is symmetric if and only if
By the transpose rule, and . If the two agree. Conversely, taking and gives and , so equality for all forces .
□Let be symmetric, and let and with . Then .
By Lemma 10.3, . So , and since , .
□Every root of the characteristic polynomial of a symmetric matrix is a real number. In particular, has at least one (real) eigenvalue, and its characteristic polynomial is a product of real linear factors.
We use complex numbers briefly, as in Remark 8.27. For a complex number ( real) its conjugate is . Then since . Equality holds only for , and is real exactly when , that is, when . Conjugation respects sums and products, and conjugating twice gives back : for complex numbers and , For we write .
Let be a root of . Then , so, by row reduction over exactly as over , there is a nonzero with . Since is real, we have
We compute in two ways. From we get . On the other hand, by the transpose rule, and , Hence .
Now , where each , with whenever ; since , the sum is positive. Therefore : the root is real.
By the fundamental theorem of algebra splits into linear factors over (Remark 8.27), and we have just seen that all the roots are real, so is a product of real linear factors. Finally, for a real root the real matrix is singular, so it has a nonzero real null vector, which is a real eigenvector (Theorem 8.16).
□A square matrix is orthogonally diagonalizable if for an orthogonal matrix and a diagonal matrix ; such a factorization is called an orthogonal decomposition of . Since for an orthogonal matrix, this is a diagonalization as in Theorem 8.30 in which the columns of are orthonormal: they form an orthonormal basis of consisting of eigenvectors of .
The proof of the spectral theorem multiplies matrices that are cut into blocks. If an matrix is written as , with a number , vectors and an matrix , then products are computed block by block, exactly as for matrices, as long as the sizes match; for instance, first the left two factors are multiplied, then the result is multiplied by the factor on the right. This follows from the row–column description of the product (Proposition 4.12): each entry of a product is a sum over one index, and grouping that sum into the first index and the remaining ones gives the block formula.
Suppose that is a real symmetric matrix. Then is orthogonally diagonalizable: (10.1) Here the are the eigenvalues of (all real), , and is an orthonormal basis of consisting of eigenvectors of .
We use induction on to prove that has an orthogonal decomposition. When , and we may take and . Let , and assume that every symmetric matrix has an orthogonal decomposition. By Lemma 10.5, has a real eigenvalue with a real eigenvector, which we normalize to a unit vector . Extend to a basis of (Theorem 6.47) and apply the Gram–Schmidt process (Theorem 9.40), which keeps the first vector, then normalize: this gives an orthonormal basis . Let with ; is an orthogonal matrix. Its columns are orthonormal, so and (the entries of are the inner products ). Since and , and . Writing with the rows and and multiplying blocks (Remark 10.7), we get Here is a symmetric matrix, since . By the induction hypothesis has an orthogonal decomposition , with orthogonal and diagonal; thus . Let The columns of are orthonormal, because those of are, so is orthogonal; and , a product of two orthogonal matrices, is orthogonal: . By Remark 10.7, Multiplying by on the left and on the right gives , an orthogonal decomposition of . This completes the induction. Finally, since , the statements about the and are Theorem 8.30 applied to .
□Let be symmetric, with orthonormal eigenvectors and eigenvalues as in (10.1). Then (10.2) where is a symmetric matrix of rank one, the matrix of the orthogonal projection onto the line . Also .
By the column view of a product, , and the rows of are . Hence because the product of a matrix with columns and a matrix with rows is : both have the entry , by Proposition 4.12.
The matrix is symmetric, since , and it has rank one, since its -th column is , a multiple of the nonzero vector , and not all these multiples are . For every , which is the projection of onto by Theorem 9.36, since is a unit vector. The same computation with gives the last statement.
□To write a symmetric matrix as :
- Find the eigenvalues; by Lemma 10.5 all roots of are real.
- For each eigenvalue find a basis of its eigenspace by row reduction.
- Apply Gram–Schmidt within each eigenspace and normalize. Eigenvectors from different eigenspaces are already orthogonal (Proposition 10.4), so only a repeated eigenvalue needs this step.
- Put the vectors into and the eigenvalues, in the same order, into ; check .
Let . Then (trace , determinant ; Example 8.18). For , , with null space spanned by ; for , , with null space spanned by . The two eigenvectors are orthogonal, as Proposition 10.4 predicts: . Normalizing, The spectral decomposition (10.2) is stretches the direction by and leaves the perpendicular direction unchanged.
Let . Expanding along the first row, So the eigenvalues are and , the latter of multiplicity . For , so . For , every row of is , so is the plane , with free; the basic solutions and form a basis of . This basis is orthogonal to , as Proposition 10.4 predicts, but it is not itself orthogonal (). Gram–Schmidt inside the eigenspace gives still an eigenvector for (a combination of ). Normalizing the three vectors gives the columns of : and with and we have . Any orthonormal basis of the plane would do for the last two columns: for a repeated eigenvalue is not unique.
A quadratic form on is a function , where is a symmetric matrix, the matrix of the form. Every homogeneous polynomial of degree in is of this kind, with a unique symmetric : the coefficient of is , and the coefficient of () is split equally, .
The form has the matrix of Example 10.11, and has the matrix of Example 10.12. The length squared, , is the form of .
Let as in (10.1). In the coordinates , that is, , the quadratic form has no cross terms: (10.3) and . The lines are the principal axes of the form.
By the transpose rule, The lengths agree by Proposition 9.20, since with orthogonal.
□A symmetric matrix , and its quadratic form, are positive definite if for every ; positive semidefinite if for every ; negative definite or semidefinite with the inequalities reversed; and indefinite if takes both positive and negative values.
A symmetric matrix is positive definite if and only if all its eigenvalues are positive, positive semidefinite if and only if all are , and indefinite if and only if it has a positive and a negative eigenvalue.
By (10.3), , and exactly when . If all , the sum is positive for . Conversely, taking (so ) gives , so a positive definite form has every . The other cases are the same argument.
□The form of Example 10.11 is positive definite (eigenvalues ), although it has the cross term . The matrix has eigenvalues and , so is indefinite: it equals at and at , even though both diagonal entries of are positive.
Let be symmetric with eigenvalues and orthonormal eigenvectors . Then for every (10.4) Consequently, on the unit sphere , the maximum of is , attained at , and the minimum is , attained at . A unit vector attains the maximum if and only if it is an eigenvector for (and likewise for the minimum).
With , (10.3) and give and . At , , so the upper bound is attained; similarly for . For a unit vector, equality on the right means , so whenever ; then is a combination of eigenvectors for , hence an eigenvector for .
□For (Example 10.14), Theorem 10.15 with the orthogonal matrix of Example 10.11 gives , and Theorem 10.19 says: subject to , the largest value of is , at , and the smallest is , at . The figure after this example shows why: the level curves are ellipses with semi-axes along and along , and the unit circle meets them only for .
For with the matrix of Example 10.12, the maximum on the unit sphere is , attained only at , and the minimum is , attained at every unit vector of the plane , because the eigenvalue has a two-dimensional eigenspace. Indeed .
What is the largest value of subject to ?
The matrix is , with eigenvalues and ; use Theorem 10.19.
Which matrix is positive definite?
Compute the eigenvalues: ; then ; then (Proposition 10.17).
Which statement about an matrix is true?
Theorem 10.8. The matrix of Lecture 8 has the real eigenvalues and is diagonalizable, but its eigenvectors and are not orthogonal.
10.2 The singular value decomposition (SVD)
Most matrices are not symmetric, not even square. Still, every matrix maps some orthonormal basis of to mutually orthogonal vectors of . To find them, note that is a quadratic form with the symmetric matrix , and use the spectral theorem. Writing with unit vectors gives : a rotation (or reflection) , then a stretch along the coordinate axes by the singular values , then another rotation . The figure in this section shows the picture in the plane: the unit circle goes to an ellipse with semi-axes and .
Let be . Then is symmetric, and all of its eigenvalues are real and nonnegative.
is symmetric by Example 10.2, so its eigenvalues are real by Lemma 10.5. Let be an eigenvalue, with a real eigenvector , so , normalized so that . Then
□Let be , and let be the eigenvalues of . The singular values of are , , listed in decreasing order (the are real and nonnegative by Lemma 10.22). If is a unit eigenvector of for , then , as in the proof of Lemma 10.22: the singular values are the lengths of the images of these eigenvectors. Exactly of them are positive. Indeed, by the spectral theorem with , so is the number of nonzero (Theorem 7.37), and by Remark 9.51.
Let be an matrix of rank , with positive singular values . Then there exist orthogonal matrices and , and a matrix with , so that (10.5)
By the spectral theorem applied to , there is an orthonormal basis of with , ordered so that ; by Definition 10.23 for and for . For , , so . For , put . These vectors are orthonormal: Extend to an orthonormal basis of (extend to a basis by Theorem 6.47, then apply Gram–Schmidt, which keeps the first vectors, and normalize). Then for and for , which says column by column: column of is for and otherwise. Since is orthogonal, .
□Let be as in Theorem 10.24.
- Since is orthogonal, (10.5) is equivalent to , which says column by column (10.6)
- Since is orthogonal, (10.5) gives , which says row by row hence, transposing,
- The columns are orthonormal eigenvectors of , the right singular vectors. The columns are normalized (indeed orthonormal) eigenvectors of , the left singular vectors: by (a) and (b), for and for . Also for . Any factorization (10.5) with orthogonal and of this shape is called a singular value decomposition (SVD) of .
- Transposing (10.5) gives , an SVD of ; so and have the same positive singular values, and by (c) the positive eigenvalues of are , with eigenvectors . To find the singular values one may therefore use the smaller of and .
In the notation of Theorem 10.24, (10.7) where and . This compact SVD uses only the positive singular values; each is a matrix of rank .
The zero rows and columns of contribute nothing to ; what is left is , expanded as in the proof of Corollary 10.9. Each has all columns multiples of , so rank .
□Let be an SVD of an matrix of rank .
- is the number of positive singular values.
- The singular vectors give orthonormal bases of the four subspaces of :
- , attained at .
- If is square (), then .
(a) This was shown in Definition 10.23.
(b) By (10.6), lie in ; they are orthonormal, hence independent, vectors, and by the rank theorem (Theorem 7.9), so they are a basis (Theorem 6.48). Then (Remark 9.25) is spanned by , which are orthogonal to and are independent vectors. Likewise for gives a basis of the -dimensional , and its orthogonal complement is spanned by the remaining .
(c) , whose maximum on the unit sphere is the largest eigenvalue of , attained at (Theorem 10.19).
(d) (Theorem 5.22), for orthogonal matrices, and .
□Read from right to left: takes the orthonormal basis to the standard basis without changing lengths or angles (Proposition 9.20); stretches the -th axis by (and drops or adds coordinates when ); takes the standard basis to the , again preserving lengths and angles. So, for an invertible matrix, maps the unit sphere onto an ellipsoid with semi-axes . Part (c) of Proposition 10.27 is the statement that the longest semi-axis has length , and part (d) matches Theorem 5.33: the volume of the ellipsoid is times that of the ball.
Let . Then with eigenvalues and and orthonormal eigenvectors , . So and . By (10.6), which are orthonormal, as the proof of Theorem 10.24 guarantees. Hence Check with part (d) of Proposition 10.27: . Note that the singular values are not the eigenvalues of , which are and .
Let , of rank . Here is but is only , so we work with : by part (d) of Remark 10.25 its positive eigenvalues are , with eigenvectors . We have whose characteristic polynomial is so and , and the eigenvectors are The right singular vectors now follow from part (b) of Remark 10.25: transposing gives . (This is the construction in the proof of Theorem 10.24 applied to , whose SVD transposes to one of .) So Finally, is a unit vector orthogonal to and ; solving , gives Hence By part (b) of Proposition 10.27, . The compact form (10.7) reads
If is symmetric with , then , so the singular values of are the absolute values of its eigenvalues; for a positive semidefinite the spectral decomposition is an SVD. In general, as in the examples, one may compute the smaller of and . Computer programs do not form at all, for the reason given in Remark 9.54; they compute the SVD directly by orthogonal transformations, and the SVD is the most reliable way to determine the rank of a matrix whose entries carry rounding errors: count the singular values that are not negligibly small.
What is the largest singular value of ?
.
What is the (only positive) singular value of the matrix ?
; use part (d) of Remark 10.25.
A matrix has singular values . What is the dimension of its null space?
The rank is the number of positive singular values (part (a) of Proposition 10.27); then use the rank theorem.
10.3 The pseudoinverse and least squares
Lecture 9 solved least-squares problems when the columns of are independent, and left open what to do when they are not (Remark 9.59): then there are infinitely many least-squares solutions, and one wants the shortest. The SVD settles this in one stroke. In the orthonormal coordinates given by and , the matrix becomes the diagonal matrix , and for a diagonal matrix the best one can do is obvious: divide by the nonzero and set the other unknowns to . Translating back gives a matrix , the pseudoinverse, with the shortest least-squares solution.
Let be an SVD of the matrix of rank . The pseudoinverse (or Moore–Penrose inverse) of is the matrix (10.8) where is the matrix with in the positions and zeros elsewhere. (One can show that does not depend on the choice of the SVD; the next theorem gives a characterization that does not mention and .)
Let be and , and let . Then:
- is a least-squares solution of ;
- , and it is the only least-squares solution in ;
- every other least-squares solution is longer: if is a least-squares solution and , then .
Change coordinates on both sides: let and , so . Since preserves lengths (Proposition 9.20) and , The last sum does not depend on , and the first is exactly when for . So the least-squares solutions are the vectors with for and arbitrary, that is, The first sum is , which proves (a). It lies in , and the second sum lies in (Proposition 10.27(b)); a least-squares solution lies in exactly when the second sum is , which proves (b). By Pythagoras (Theorem 9.11), , which proves (c).
□Let be of rank .
- is the matrix of the orthogonal projection onto , and is the matrix of the orthogonal projection onto .
- If the columns of are independent (), then , and is the of Lecture 9.
- If the rows of are independent (), then , and is consistent for every , with shortest solution .
- If is square and invertible, then .
(a) By (10.7) and (10.8), because (Lemma 9.15). By Theorem 9.36 this is the matrix of the projection onto , which is by part (b) of Proposition 10.27. Similarly .
(b) If , the least-squares solution is unique (Theorem 9.52) and equals ; by Theorem 10.33 it is also , for every , so the two matrices are equal (take ).
(c) If , then , so every is in it and the least-squares solutions are the solutions. Apply (b) to , whose columns are independent: , and by (10.8) and part (d) of Remark 10.25; transposing gives the formula.
(d) If is invertible, the unique solution of is its unique least-squares solution, so for every .
□In Remark 9.59, and had the least-squares solutions , and the shortest one was found to be . Here has the eigenvalues and , with ; so , , and . By (10.8), the same answer, now from a formula. Also , where is the matrix of ones; this is the matrix of the projection onto the line (part (a) of Proposition 10.34). It sends to each entry of is replaced by the mean of its entries. So the best the columns of can do for this is the constant vector .
For the matrix of Example 10.30 and , the system is consistent (the rows of are independent) with infinitely many solutions, since . The shortest one is given by the proof of Theorem 10.33: with and , Check: and , so . The same matrix comes from part (c) of Proposition 10.34: Every other solution , , has length squared .
The factors in (10.8) show the danger of a nearly dependent set of columns: a tiny but nonzero , perhaps produced by rounding, multiplies the component of the data by a huge number. In practice one therefore treats singular values below a tolerance as (a truncated pseudoinverse); this replaces by a nearby matrix of lower rank, which is the subject of Section 10.4.
What is the entry of the pseudoinverse of ?
inverts the nonzero diagonal entries and keeps the zeros.
The equation has infinitely many solutions. What is the first entry of the shortest one, with and ?
The shortest solution lies in .
10.4 Best approximation by matrices of low rank
The compact SVD writes as a sum of rank-one pieces , ordered by importance. Keeping only the first pieces gives a matrix of rank that is cheap to store, numbers instead of , and the Eckart–Young theorem says that no matrix of rank is closer to . This is the mathematics behind image compression, behind the principal components of a data set, and behind the “latent factors” of recommendation systems. To speak of “closer” we first need the size of a matrix.
For an matrix :
- the Frobenius norm is , the length of viewed as a vector of entries;
- the spectral norm (or operator norm) is , the largest factor by which stretches a vector.
If has singular values , then
The first is part (c) of Proposition 10.27. For the second, note that is the sum of the squared lengths of the columns of , and also of the rows of . If is orthogonal, the columns of are times the columns of and have the same lengths (Proposition 9.20), so . Likewise the rows of are the transposes of times the rows of , so for orthogonal . Hence , and .
□For let (10.9) the first terms of (10.7). It has rank , its SVD is that of with replaced by , and has the singular values . Storing takes the numbers and the entries of and .
Let be with singular values , let , and let be as in (10.9).
- and .
- For every matrix of rank at most , .
- For every matrix of rank at most , .
(a) is Proposition 10.39 applied to , whose singular values are (Definition 10.40).
(b) has rank at most , so by the rank theorem. The subspace has dimension . Since , the two subspaces have a common nonzero vector. Indeed, if , then a basis of together with would be independent (in a dependence relation, the part in equals minus the part in , so both parts are and all coefficients vanish), and these are more than vectors in , which is impossible. Choose a vector with , and write since the are orthonormal. Then , and by (10.6) Since the are orthonormal, this equals Hence .
(c) This is the Eckart–Young–Mirsky theorem. Its proof uses more refined inequalities between the singular values of , and , and is omitted here.
□For of Example 10.30, with and , By Theorem 10.41, , and no rank-one matrix is closer to . Check with Proposition 10.39:
A grayscale image is a matrix of brightness values. The figure after this example shows a picture and its truncated SVDs. Its singular values decrease quickly: , , , , and from the eighth on they are below . By Theorem 10.41(a) the error of is , so a fast decay of the singular values means that a small suffices. The rank- image is a product of a column profile and a row profile, hence the stripes; each further term adds detail.
Let the rows of be data points in the plane with mean : For a line through the origin, with , the squared distance from a point to the line is (Pythagoras for the split of Remark 9.13). Summing over the rows of , since the entries of are the numbers . This is smallest when is largest, that is, for (Proposition 10.27(c)), and the minimum is . Here has eigenvalues and with : the best line is , and the sum of the squared perpendicular distances is . The least-squares line of Lecture 9, which measures vertical distances, is different: its normal equation is , so , with the sum of squared vertical distances . The direction is the first principal component of the data; in statistics this is principal component analysis.
A matrix has singular values . What is , the squared Frobenius error of its best rank-one approximation?
Theorem 10.41(a): .
How many numbers must be stored for the rank- approximation of a matrix?
with , , (Definition 10.40).
A matrix has singular values . What is over all matrices of rank at most ?
Theorem 10.41: the minimum is , attained at .
The course began with the system and row reduction, which reveals the rank and the four subspaces of . The SVD reveals the same information, but with orthonormal bases and with the singular values measuring how strongly acts in each direction. That is why it is the tool of choice whenever the data are inexact: it gives the shortest least-squares solution, the numerical rank, and the best approximations of lower rank.
Index of statements
- Definition 10.1 (Symmetric matrix)
- Example 10.2 (Where symmetric matrices come from)
- Lemma 10.3 (Symmetric matrices move across the inner product)
- Proposition 10.4 (Eigenvectors of a symmetric matrix are orthogonal)
- Lemma 10.5 (A symmetric matrix has real eigenvalues)
- Definition 10.6 (Orthogonally diagonalizable)
- Remark 10.7 (Block matrices)
- Theorem 10.8 (The spectral theorem)
- Corollary 10.9 (Spectral decomposition)
- Remark 10.10 (How to diagonalize a symmetric matrix orthogonally)
- Example 10.11 (A symmetric matrix)
- Example 10.12 (A repeated eigenvalue)
- Definition 10.13 (Quadratic form)
- Example 10.14 (The matrix of a quadratic form)
- Theorem 10.15 (Principal axes)
- Definition 10.16 (Definite and indefinite forms)
- Proposition 10.17 (Definiteness from the eigenvalues)
- Example 10.18 (Definite and indefinite)
- Theorem 10.19 (Maximum and minimum of a quadratic form)
- Example 10.20 (Extremes on the unit circle)
- Example 10.21 (Extremes in three variables)
- Lemma 10.22 (The matrix )
- Definition 10.23 (Singular values)
- Theorem 10.24 (The singular value decomposition (SVD))
- Remark 10.25 (Singular vectors)
- Corollary 10.26 (The SVD as a sum of rank-one matrices)
- Proposition 10.27 (What the SVD tells us)
- Remark 10.28 (The geometry of the SVD)
- Example 10.29 (An SVD of a matrix)
- Example 10.30 (An SVD of a matrix)
- Remark 10.31 (Symmetric matrices, and computing the SVD)
- Definition 10.32 (The pseudoinverse)
- Theorem 10.33 (The shortest least-squares solution)
- Proposition 10.34 (Properties of the pseudoinverse)
- Example 10.35 (Lecture 9's example with dependent columns)
- Example 10.36 (A system with more unknowns than equations)
- Remark 10.37 (Small singular values)
- Definition 10.38 (Two norms of a matrix)
- Proposition 10.39 (The norms from the singular values)
- Definition 10.40 (Truncated SVD)
- Theorem 10.41 (Eckart–Young: best approximation of low rank)
- Example 10.42 (The best rank-one approximation of )
- Example 10.43 (Image compression)
- Example 10.44 (The best line through data points)
- Remark 10.45 (Looking back)