Linear Algebra / Unit 7, Symmetric Matrices / Topic 7.3
Unit 7. Symmetric Matrices
The spectral theorem diagonalizes a symmetric matrix with one orthonormal basis. The singular value decomposition does the same work for any matrix, of any shape, by using two orthonormal bases. It writes each matrix as A = UΣVT. This topic builds the factorization, shows what it means in a picture, and uses it to find the rank, the best approximation of a matrix, and the solution of least squares problems that Topic 6.4 could not finish.
You need Topics 4.4, 6.3, 6.4, 7.1, and 7.2 for this topic.
An eigenvector equation Ax = λx needs a square matrix, because the input and the output must be in the same space. Even for a square matrix, the eigenvectors are usually not perpendicular, and sometimes there are not enough of them.
The singular value decomposition uses one orthonormal basis v₁, v₂, … for the inputs and another orthonormal basis u₁, u₂, … for the outputs. The matrix sends each input basis vector to a multiple of the matching output basis vector.
Avi = σiuiThe numbers σ₁, σ₂, … are called the singular values of A. They are never negative, and they are listed from the largest to the smallest. The vectors vi are called the right singular vectors, and the vectors ui are called the left singular vectors.
From Topic 7.2, the matrix ATA is symmetric and positive semidefinite for any matrix A. By the spectral theorem, it has orthonormal eigenvectors, and its eigenvalues are not negative.
The vectors ui built this way are orthonormal. For two different indexes i and j,
(Avi) · (Avj) = vi · (ATAvj)move A to the other side as its transpose(Avi) · (Avj) = σj²(vi · vj)vj is an eigenvector of ATA(Avi) · (Avj) = 0the eigenvectors are perpendicularWith i = j, the same calculation gives |Avi|² = σi², so the length of Avi is σi, and ui is a unit vector.
The eigenvalues of ATA are 45 and 5, with the unit eigenvectors v₁ = (1, 1)/√2 and v₂ = (−1, 1)/√2. The singular values are σ₁ = √45, which is about 6.71, and σ₂ = √5, which is about 2.24.
Av₁ = 1/√2 39multiplyu₁ = 1/√10 13divide by σ₁ = √45Av₂ = 1/√2 −31multiplyu₂ = 1/√10 −31divide by σ₂ = √5The vectors u₁ and u₂ are perpendicular unit vectors, as Part 2 showed.
The eigenvalues of A itself are 3 and 5, because A is triangular. The singular values are different numbers. The product is the same in size: σ₁σ₂ = √225 = 15, and the determinant of A is 15.
Put the vectors vi in the columns of a matrix V, and the vectors ui in the columns of a matrix U. Put the singular values on the diagonal of a matrix Σ. The equations Avi = σiui, written together, are AV = UΣ. The matrix V is orthogonal, so multiplying by VT on the right gives the factorization.
The singular value decomposition. Each matrix A can be written as A = UΣVT. The matrices U and V are orthogonal, and Σ is zero except for the singular values on its diagonal.
For the example,
U = 1/√10 1−331 Σ = √4500√5 VT = 1/√2 11−11The three factors act one after another, from right to left.
Any map of the plane is a turn or a reflection, then a stretch along the axes, then another turn or reflection. The unit circle goes to an ellipse. The half-lengths of its axes are the singular values, and the axes point along u₁ and u₂.
Try it: the singular vectors of a matrix
The sliders set the entries of the matrix with the rows a, b and c, d. The dashed arrows on the gray unit circle are the input vectors v₁ and v₂. The solid arrows are their images σ₁u₁ and σ₂u₂, which are the half-axes of the green ellipse. The drawing starts with one half of the matrix of Part 3, so that the ellipse fits on the grid.
The construction of Part 2 never used a square matrix. For a matrix with m rows and n columns, V is n by n, U is m by m, and Σ has the same shape as A.
The number of singular values that are not zero is the rank r of the matrix. The singular vectors give orthonormal bases for the four subspaces of Topic 4.4.
| Vectors | Subspace |
|---|---|
| v₁, …, vr | The row space of A |
| The remaining vectors v | The null space of A |
| u₁, …, ur | The column space of A |
| The remaining vectors u | The left null space of A |
Multiplying out UΣVT gives one term for each singular value that is not zero.
A = σ₁u₁v₁T + σ₂u₂v₂T + … + σrurvrTEach term is a matrix of rank 1. This is the same kind of sum as the sum of projections in Topic 7.1, with two sets of vectors.
The eigenvalues of ATA are 25 and 0, so σ₁ = 5 and σ₂ = 0. The rank is 1. The vector v₁ = (1, 2)/√5 is the unit vector along the row space, and u₁ = Av₁/5 = (1, 2)/√5 is the unit vector along the column space. The whole matrix is the single term A = 5u₁v₁T.
The terms of the sum are ordered by size, because σ₁ is the largest singular value. Keeping only the first k terms gives a matrix of rank k. A theorem of Eckart and Young states that this matrix is the closest matrix of rank k to A.
A photograph is a matrix of brightness values. When its singular values fall quickly, a few terms of the sum reproduce the picture well, and the terms need much less storage than the full matrix. In statistics, the same idea finds the directions in which a set of data varies the most, which is called principal component analysis.
The largest singular value has a direct meaning: σ₁ is the largest value of |Ax| over all unit vectors x. It measures the largest stretch that the matrix can produce.
Topic 6.4 solved Ax = b in the least squares sense when the columns of A are independent. When the columns are dependent, many vectors give the same smallest error, and Topic 6.4 left the choice open. The singular value decomposition makes the choice.
The pseudoinverse of A is written A⁺. It inverts A on the part where A can be inverted, and it sends the rest to zero. Each nonzero singular value σ is replaced by 1/σ, and the roles of U and V are exchanged.
A⁺ = 1/σ₁v₁u₁T + … + 1/σrvrurTThe vector A⁺b is a least squares solution of Ax = b. Among all of the least squares solutions, it is the one with the smallest length. It lies in the row space, and it has no part in the null space.
For the matrix with the rows 1, 2 and 2, 4, the pseudoinverse is (1/5)v₁u₁T.
A⁺ = 1/25 1224 b = 510 A⁺b = 12The system is x + 2y = 5, written twice. Its solutions are (5, 0) + t(−2, 1). The pseudoinverse picks (1, 2), which is the solution that is perpendicular to the null space direction (−2, 1). No other solution is shorter.
When A is square and invertible, the pseudoinverse is the inverse. When A has independent columns, the pseudoinverse gives the least squares solution of Topic 6.4.
| Fact | Statement |
|---|---|
| Singular value decomposition | A = UΣVT, with orthogonal U and V |
| Singular values | The square roots of the eigenvalues of ATA, never negative |
| Singular vectors | Avi = σiui |
| Picture | A turn, a stretch along the axes, and another turn. The unit circle goes to an ellipse with the half-lengths σ₁ and σ₂ |
| Rank | The number of singular values that are not zero |
| Best approximation | The first k terms of σ₁u₁v₁T + σ₂u₂v₂T + … |
| Pseudoinverse | A⁺b is the shortest least squares solution of Ax = b |
Work each problem on paper first. Then open the answer to check your work.
ATA is the diagonal matrix with the entries 4 and 9. The singular values are the square roots, listed from the largest: 3 and 2.
The eigenvalue −3 of A gives the singular value 3. A singular value is never negative.
ATA = 1004the eigenvalues are 4 and 1σ₁ = 2with v₁ = (0, 1)σ₂ = 1with v₂ = (1, 0)u₁ = Av₁/2 = (1, 0)u₂ = Av₂/1 = (0, 1)
U = I, Σ = 2001, and VT = 0110.
ATA = 1112, with the trace 3 and the determinant 1. Its eigenvalues are (3 + √5)/2 and (3 − √5)/2, which are about 2.618 and 0.382.
The singular values are the square roots, about 1.618 and 0.618. Their product is 1, which is the determinant of the shear.
ATA = 9121216the eigenvalues are 25 and 0σ₁ = 5with v₁ = (0.6, 0.8)u₁ = Av₁/5 = (1/5)(5, 0) = (1, 0)
The matrix is 5u₁v₁T.
A⁺b = 1/25 1224 50A⁺b = (0.2, 0.4)
The two equations cannot both be true. The vector (0.2, 0.4) gives the smallest error, and it is the shortest vector that does so.
Let ATAv = λv with λ not zero. Multiply both sides by A: AAT(Av) = λ(Av).
The vector Av is not zero, because ATAv is not zero. So Av is an eigenvector of AAT with the same eigenvalue λ.
The instruction np.linalg.svd gives three results. The first is the matrix U. The second is the list of singular values, from the largest to the smallest. The third is VT, which is already transposed. Three names with commas between them receive the three results.
Python
The singular values are 6.708 and 2.236, which are √45 and √5, as in Part 3. Python can give a column of U and the matching row of VT with the opposite signs. The product is the same.
Now find the singular values of the shear of Practice Problem 3, with the rows 1, 1 and 0, 1.
Python
The instruction np.diag(s) makes the diagonal matrix Σ from the list of singular values. The product UΣVT should give the matrix A back.
Python
The result is the matrix A, apart from very small rounding errors.
From Part 2, the singular values are the square roots of the eigenvalues of ATA. The instruction np.linalg.eigvalsh lists those eigenvalues from the smallest to the largest.
Python
The eigenvalues of ATA are 5 and 45, and their square roots are the singular values. The last line prints the eigenvalues of A itself, which are 3 and 5. They are not the singular values.
The matrix below has 3 rows and 3 columns, but its third row is 2 times the second row minus the first row, so its rank is 2. The third singular value shows this.
Python
The third singular value is 0, so the rank is 2. The first singular value is much larger than the second, so the first term of the sum in Part 5 is already close to A. The code below calculates that term. Here U[:, 0] is the first column of U, and Vt[0] is the first row of VT.
Python
Each entry of this rank 1 matrix is close to the matching entry of A. Now add the second term, so that B holds the first two terms of the sum. The result should be A itself, because the third singular value is 0.
Python
The instruction np.linalg.pinv calculates the pseudoinverse of Part 7. The code below uses the rank 1 matrix of that part. The instruction np.linalg.solve cannot solve this system, because the matrix has no inverse.
Python
The pseudoinverse has the entries 0.04, 0.08, 0.08, and 0.16, which is the matrix A divided by 25. The solution is (1, 2). Now change the right side to (5, 0), as in Practice Problem 5. That system has no exact solution.
Python
The result (0.2, 0.4) is the shortest vector that makes the error as small as possible.
This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.
Choose how your answers are checked
1. Find the singular values of 03−20.
AT A is the diagonal matrix with the entries 4 and 9. The singular values are the square roots of its eigenvalues, 3 and 2.
2. The singular values of a matrix A are which numbers?
The vectors v are the eigenvectors of AT A, and each singular value is the square root of the matching eigenvalue. The eigenvalues of A itself are usually different numbers.
3. The singular values of a 2 by 2 matrix are 6 and 2. Find the absolute value of its determinant.
In A = UΣVT, the determinants of the orthogonal matrices U and VT are 1 or −1, and the determinant of Σ is (6)(2) = 12. So the determinant of A is 12 or −12.
4. A matrix with 3 rows and 5 columns has the singular values 4, 2, and 0. What is its rank?
The rank is the number of singular values that are not zero. Two of the three singular values are not zero.
5. Let A = 1224 and b = (0, 5). Find the vector A⁺b, where A⁺ is the pseudoinverse of A.
For this matrix, A⁺ = (1/25)A.Ab = (10, 20)A⁺b = (1/25)(10, 20) = (0.4, 0.8)This is the shortest least squares solution of Ax = b.