Math Core

Lesson 7.3 · Symmetric Matrices

The singular value decomposition

Diagonalization only works for some square matrices, and orthogonal diagonalization only for symmetric ones. The singular value decomposition (SVD) works for every matrix, of any shape. It says that any linear map, viewed in the right orthonormal bases for its input and output spaces, simply stretches along perpendicular directions. The SVD powers image compression, principal component analysis, recommendation systems, and the numerical computation of rank.

Singular values

Let AA be an m×nm \times n matrix. The matrix ATAA^TA is n×nn \times n and symmetric, so it has an orthonormal eigenbasis v1,…,vn\mathbf{v}_1, \ldots, \mathbf{v}_n with real eigenvalues λ1,…,λn\lambda_1, \ldots, \lambda_n. These eigenvalues are never negative, because for a unit eigenvector vi\mathbf{v}_i,

∥Avi∥2=(Avi)T(Avi)=viT(ATAvi)=λiviTvi=λi.\|A\mathbf{v}_i\|^2 = (A\mathbf{v}_i)^T(A\mathbf{v}_i) = \mathbf{v}_i^T(A^TA\mathbf{v}_i) = \lambda_i\mathbf{v}_i^T\mathbf{v}_i = \lambda_i.

Definition

Singular values

The singular values of AA are the square roots of the eigenvalues of ATAA^TA, listed in decreasing order:

σ1≥σ2≥⋯≥σn≥0,σi=λi.\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_n \ge 0, \qquad \sigma_i = \sqrt{\lambda_i}.

By the computation above, σi=∥Avi∥\sigma_i = \|A\mathbf{v}_i\|: the singular value is the length of AA applied to the unit eigenvector vi\mathbf{v}_i.

Two more facts follow quickly. First, for i≠ji \ne j, (Avi)⋅(Avj)=viTATAvj=λj(vi⋅vj)=0(A\mathbf{v}_i) \cdot (A\mathbf{v}_j) = \mathbf{v}_i^TA^TA\mathbf{v}_j = \lambda_j(\mathbf{v}_i \cdot \mathbf{v}_j) = 0, so the vectors Av1,…,AvnA\mathbf{v}_1, \ldots, A\mathbf{v}_n are orthogonal. Second, the nonzero ones among them form a basis for Col⁡A\operatorname{Col}A, so

rank⁡A=the number of nonzero singular values.\operatorname{rank}A = \text{the number of nonzero singular values}.

The singular values also measure stretching. By the constrained extremes result from the last lesson applied to ∥Ax∥2=xT(ATA)x\|A\mathbf{x}\|^2 = \mathbf{x}^T(A^TA)\mathbf{x}, the largest value of ∥Ax∥\|A\mathbf{x}\| over unit vectors x\mathbf{x} is σ1\sigma_1, reached at x=v1\mathbf{x} = \mathbf{v}_1, and the smallest is σn\sigma_n.

The decomposition

Suppose AA has rank rr, so σ1,…,σr\sigma_1, \ldots, \sigma_r are positive and the rest are 00. Normalize the orthogonal vectors AviA\mathbf{v}_i:

ui=1σiAvi(i=1,…,r).\mathbf{u}_i = \frac{1}{\sigma_i}A\mathbf{v}_i \qquad (i = 1, \ldots, r).

These are orthonormal vectors in Rm\mathbb{R}^m. If r<mr < m, extend them to an orthonormal basis u1,…,um\mathbf{u}_1, \ldots, \mathbf{u}_m of Rm\mathbb{R}^m. Since Avi=σiuiA\mathbf{v}_i = \sigma_i\mathbf{u}_i for every ii (both sides are 0\mathbf{0} when i>ri > r), putting these equations side by side gives AV=UΣAV = U\Sigma, and multiplying on the right by VT=V−1V^T = V^{-1} gives the theorem.

The singular value decomposition

Every m×nm \times n matrix AA of rank rr can be factored as

A=UΣVT,A = U\Sigma V^T,

where

  • VV is an n×nn \times n orthogonal matrix whose columns vi\mathbf{v}_i (the right singular vectors) are an orthonormal eigenbasis of ATAA^TA;
  • Σ\Sigma is the m×nm \times n matrix with σ1,…,σr\sigma_1, \ldots, \sigma_r in the first rr diagonal positions and zeros everywhere else;
  • UU is an m×mm \times m orthogonal matrix whose first rr columns (the left singular vectors) are ui=1σiAvi\mathbf{u}_i = \frac{1}{\sigma_i}A\mathbf{v}_i.

Read right to left, Ax=UΣVTxA\mathbf{x} = U\Sigma V^T\mathbf{x} says: rotate (or reflect) with VTV^T, stretch along the coordinate axes by the singular values with Σ\Sigma, then rotate (or reflect) with UU. In particular, AA maps the unit circle to an ellipse whose semi-axes are σ1u1\sigma_1\mathbf{u}_1 and σ2u2\sigma_2\mathbf{u}_2.

The recipe

  1. Compute ATAA^TA and its eigenvalues. Order them from largest to smallest.
  2. Find an orthonormal eigenvector vi\mathbf{v}_i for each eigenvalue. These are the columns of VV.
  3. The singular values are σi=λi\sigma_i = \sqrt{\lambda_i}. Build Σ\Sigma with the same shape as AA.
  4. For each nonzero σi\sigma_i, compute ui=Avi/σi\mathbf{u}_i = A\mathbf{v}_i / \sigma_i. If you need more columns for UU, complete to an orthonormal basis of Rm\mathbb{R}^m.

Worked example: A square matrix

Find an SVD of A=[3045]A = \begin{bmatrix} 3 & 0 \\ 4 & 5 \end{bmatrix}.

ATA=[3405][3045]=[25202025].A^TA = \begin{bmatrix} 3 & 4 \\ 0 & 5 \end{bmatrix}\begin{bmatrix} 3 & 0 \\ 4 & 5 \end{bmatrix} = \begin{bmatrix} 25 & 20 \\ 20 & 25 \end{bmatrix}.

Its eigenvalues are 4545 (eigenvector (1,1)(1, 1)) and 55 (eigenvector (−1,1)(-1, 1)). So σ1=45=35\sigma_1 = \sqrt{45} = 3\sqrt{5}, σ2=5\sigma_2 = \sqrt{5}, and

v1=12(1,1),v2=12(−1,1).\mathbf{v}_1 = \tfrac{1}{\sqrt{2}}(1, 1), \qquad \mathbf{v}_2 = \tfrac{1}{\sqrt{2}}(-1, 1).

Next, Av1=12(3,9)A\mathbf{v}_1 = \tfrac{1}{\sqrt{2}}(3, 9), so u1=135⋅12(3,9)=110(1,3)\mathbf{u}_1 = \dfrac{1}{3\sqrt{5}} \cdot \tfrac{1}{\sqrt{2}}(3, 9) = \tfrac{1}{\sqrt{10}}(1, 3). And Av2=12(−3,1)A\mathbf{v}_2 = \tfrac{1}{\sqrt{2}}(-3, 1), so u2=110(−3,1)\mathbf{u}_2 = \tfrac{1}{\sqrt{10}}(-3, 1). Therefore

A=110[1−331]⏟U[35005]⏟Σ12[11−11]⏟VT.A = \underbrace{\frac{1}{\sqrt{10}}\begin{bmatrix} 1 & -3 \\ 3 & 1 \end{bmatrix}}_{U}\underbrace{\begin{bmatrix} 3\sqrt{5} & 0 \\ 0 & \sqrt{5} \end{bmatrix}}_{\Sigma}\underbrace{\frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ -1 & 1 \end{bmatrix}}_{V^T}.

As a check, σ1σ2=15=∣det⁡A∣\sigma_1\sigma_2 = 15 = |\det A|. This always happens for square matrices, since ∣det⁡U∣=∣det⁡V∣=1|\det U| = |\det V| = 1.

Worked example: A wide matrix

Find an SVD of A=[110011]A = \begin{bmatrix} 1 & 1 & 0 \\ 0 & 1 & 1 \end{bmatrix}.

ATA=[110121011].A^TA = \begin{bmatrix} 1 & 1 & 0 \\ 1 & 2 & 1 \\ 0 & 1 & 1 \end{bmatrix}.

You can check that its eigenvalues are 33, 11 and 00, with orthonormal eigenvectors

v1=16(1,2,1),v2=12(1,0,−1),v3=13(1,−1,1).\mathbf{v}_1 = \tfrac{1}{\sqrt{6}}(1, 2, 1), \qquad \mathbf{v}_2 = \tfrac{1}{\sqrt{2}}(1, 0, -1), \qquad \mathbf{v}_3 = \tfrac{1}{\sqrt{3}}(1, -1, 1).

(For instance, ATA(1,2,1)=(3,6,3)A^TA(1, 2, 1) = (3, 6, 3).) The singular values are 3\sqrt{3}, 11 and 00, so AA has rank 22. Then Av1=16(3,3)A\mathbf{v}_1 = \tfrac{1}{\sqrt{6}}(3, 3), which divided by 3\sqrt{3} gives u1=12(1,1)\mathbf{u}_1 = \tfrac{1}{\sqrt{2}}(1, 1), and Av2=12(1,−1)=u2A\mathbf{v}_2 = \tfrac{1}{\sqrt{2}}(1, -1) = \mathbf{u}_2. Since AA is 2×32 \times 3, Σ\Sigma is 2×32 \times 3:

A=12[111−1][300010][1/62/61/61/20−1/21/3−1/31/3].A = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}\begin{bmatrix} \sqrt{3} & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}\begin{bmatrix} 1/\sqrt{6} & 2/\sqrt{6} & 1/\sqrt{6} \\ 1/\sqrt{2} & 0 & -1/\sqrt{2} \\ 1/\sqrt{3} & -1/\sqrt{3} & 1/\sqrt{3} \end{bmatrix}.

The vector v3\mathbf{v}_3, which has singular value 00, spans Nul⁡A\operatorname{Nul}A.

Common mistake

Singular values are not the eigenvalues of AA. They are the square roots of the eigenvalues of ATAA^TA. For example, [0100]\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} has only the eigenvalue 00, but its singular values are 11 and 00. The one exception: for a symmetric matrix, the singular values are the absolute values of the eigenvalues.

The SVD as a sum, and low-rank approximation

Multiplying out UΣVTU\Sigma V^T column-by-row gives the outer-product form

A=σ1u1v1T+σ2u2v2T+⋯+σrurvrT,A = \sigma_1\mathbf{u}_1\mathbf{v}_1^T + \sigma_2\mathbf{u}_2\mathbf{v}_2^T + \cdots + \sigma_r\mathbf{u}_r\mathbf{v}_r^T,

a sum of rr rank-one matrices, from most important to least. Keeping only the first kk terms gives a matrix AkA_k of rank kk, and it can be proved that AkA_k is the closest rank-kk matrix to AA. This is how the SVD compresses data: a 1000×10001000 \times 1000 image stored as k=50k = 50 terms needs about 50⋅2001≈100,00050 \cdot 2001 \approx 100{,}000 numbers instead of 1,000,0001{,}000{,}000.

Worked example: A rank-one matrix

Find the singular values of A=[221122]A = \begin{bmatrix} 2 & 2 \\ 1 & 1 \\ 2 & 2 \end{bmatrix} and write AA in outer-product form.

ATA=[9999]A^TA = \begin{bmatrix} 9 & 9 \\ 9 & 9 \end{bmatrix} has eigenvalues 1818 and 00, with v1=12(1,1)\mathbf{v}_1 = \tfrac{1}{\sqrt{2}}(1, 1). So σ1=18=32\sigma_1 = \sqrt{18} = 3\sqrt{2} and σ2=0\sigma_2 = 0; the rank is 11.

Av1=12(4,2,4)A\mathbf{v}_1 = \tfrac{1}{\sqrt{2}}(4, 2, 4), and dividing by 323\sqrt{2} gives u1=13(2,1,2)\mathbf{u}_1 = \tfrac{1}{3}(2, 1, 2). Therefore

A=32 u1v1T=32⋅13[212]12[11]=[212][11].A = 3\sqrt{2}\,\mathbf{u}_1\mathbf{v}_1^T = 3\sqrt{2} \cdot \frac{1}{3}\begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix}\frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix}\begin{bmatrix} 1 & 1 \end{bmatrix}.

For a full SVD, UU must be 3×33 \times 3: extend u1\mathbf{u}_1 with any orthonormal basis of the plane perpendicular to it, such as 12(1,0,−1)\tfrac{1}{\sqrt{2}}(1, 0, -1) and 132(1,−4,1)\tfrac{1}{3\sqrt{2}}(1, -4, 1).

Tip

Useful checks: σ12+⋯+σn2\sigma_1^2 + \cdots + \sigma_n^2 equals the sum of the squares of all entries of AA (it is the trace of ATAA^TA). In the first example, 45+5=50=9+0+16+2545 + 5 = 50 = 9 + 0 + 16 + 25.

Practice

Practice 1

Find the singular values of A=[0−320]A = \begin{bmatrix} 0 & -3 \\ 2 & 0 \end{bmatrix}.

Separate answers with commas, e.g. 2, -5

Practice 2

Find the largest singular value of A=[403−5]A = \begin{bmatrix} 4 & 0 \\ 3 & -5 \end{bmatrix}.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Let A=[122−2]A = \begin{bmatrix} 1 & 2 \\ 2 & -2 \end{bmatrix}. Find the maximum of ∥Ax∥\|A\mathbf{x}\| over all unit vectors x\mathbf{x}.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 4

Find the singular values of A=[110110]A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \\ 1 & 0 \end{bmatrix}.

Separate answers with commas, e.g. 2, -5

Practice 5

A 4×54 \times 5 matrix AA has singular values 7,3,0,0,07, 3, 0, 0, 0. What is the dimension of Nul⁡A\operatorname{Nul}A?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

The matrix A=[6−483]A = \begin{bmatrix} 6 & -4 \\ 8 & 3 \end{bmatrix} has ATA=[1000025]A^TA = \begin{bmatrix} 100 & 0 \\ 0 & 25 \end{bmatrix}. Find the (2,1)(2, 1) entry of the best rank-one approximation A1=σ1u1v1TA_1 = \sigma_1\mathbf{u}_1\mathbf{v}_1^T.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

A 3×33 \times 3 matrix AA has singular values 55, 22 and 12\tfrac{1}{2}. Find ∣det⁡A∣|\det A|.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

Let AA be an m×nm \times n matrix with SVD A=UΣVTA = U\Sigma V^T. Which statement is true?