Singular value decomposition
The question
Can you recreate a matrix's effect on a circle and its marked arrows?
- 1 SeeMatch the outline and its arrows.
- 2 TryTest what changes when directions collapse.
- 3 ProveBuild the factorization from dot products.
- 4 ApplyUse the factors on real data.
Before you start · 3 quick checks on matrix columns, dot products, and eigenvectors, about 3 min
Two ideas before you start
2 ideasA turn preserves length
A fixed input arrow and its image after a plane rotation.
The dashed arrow turns about the origin. Its length stays the same.
Exact definition
A real square matrix \(Q\) is orthogonal if \(Q^TQ=I\), where \(Q^T\) swaps rows with columns and \(I\) is the identity map. Its columns form an orthonormal basis. Each column has length one, and any two distinct columns have dot product zero.
For any inputs \(x,y\), the dot product of their images is \((Qx)^T(Qy)=x^Ty\). Taking the same vector twice gives preservation of squared length. A plane rotation is an example.
A diagonal stretch changes coordinates separately
A fixed input arrow and its image with only the horizontal coordinate scaled.
Change the horizontal stretch and watch the dashed tip move along a horizontal line.
Exact definition
In the plane, \(\operatorname{diag}(s,t)\) is a diagonal matrix with entries \(s,t\) on its diagonal and zero elsewhere. It sends \((x,y)\) to \((sx,ty)\). The same rule scales each coordinate in higher dimensions. A rectangular diagonal matrix also drops any extra input coordinates or pads the output with zeros as its dimensions require.
Refresher on symmetric matrices
A real square matrix \(G\) is symmetric when \(G^T=G\). The real spectral theorem says that its space has an orthonormal basis of eigenvectors \(v_i\), with real eigenvalues \(\lambda_i\) satisfying \(Gv_i=\lambda_i v_i\). Within a repeated eigenspace, choose any orthonormal basis. The proof uses this theorem for a symmetric matrix formed from the original map.
See symmetric matrices and their eigenvector directions for the spectral theorem and its geometry.
Match the target ellipse and its arrows
- Drag the input and output turn sliders. Positive angles turn counterclockwise. You can also type a setting or use the arrow keys.
- Set the horizontal and vertical stretches. Switch views to inspect the intermediate shapes.
- Press Check my settings to see which stages match a common decomposition.
Read the stage matches
The input frame turns the marked points on the circle before any stretching. The thick arrow starts on the positive horizontal axis. The thin arrow starts on the positive vertical axis. At the end their tips are the columns of the map you built.
The status compares your settings with a single valid decomposition at a time. It picks one that matches the most stages and breaks a tie by proximity to your settings. Swapping the two scales works when the input and output axes are also swapped. Reversing the same singular direction in both frames also works. The reflection switch reverses the second intermediate coordinate in both frames, right after the input turn and right before the output turn.
Show one set of matching settings
Enter these settings and inspect the intermediate views. Now switch on the reflections and look at the input-frame view again. The first reflection changes an intermediate coordinate. The second undoes that sign change after the diagonal stretch, so the final arrows still match.
Which operations does this map need?
Check your prediction to open the shape controls.
- Change either stretch and check the shape and rank.
- Turn the output and compare the thick arrow with the outline.
Why a stretch can remove a dimension
Here the input frame is fixed at the identity. With two positive stretches, the map sends the plane onto the plane. With one positive stretch, the unit circle maps onto a segment whose length is twice that stretch, and the whole plane maps onto the line containing the segment. With both stretches zero, every input goes to the origin.
Rank is the dimension of the space reached by the map, so it counts the positive stretches. An orthogonal map at either end of the stretch leaves that count unchanged. When both stretches are equal and positive, all directions stretch by the same factor. The outline can stay fixed while a marked arrow turns.
Find the input and output frames
Let \(A\) be any real \(m\)-by-\(n\) matrix with \(m,n\ge1\). There are orthogonal matrices \(U\) of size \(m\)-by-\(m\) and \(V\) of size \(n\)-by-\(n\) and an \(m\)-by-\(n\) diagonal matrix \(\Sigma\) such that
\[A=U\Sigma V^T.\]The \(\min(m,n)\) diagonal entries of \(\Sigma\), in nonincreasing order, are the singular values. They are the square roots of the largest \(\min(m,n)\) eigenvalues of \(A^TA\), counted with multiplicity. All are nonnegative, and the number of positive singular values is the rank of \(A\). The map can be rectangular, rank deficient, or zero.
Set \(G=A^TA\). Its orthonormal eigenvectors \(v_i\) have eigenvalues \(\lambda_i\). Pick the next statement at each step. When a line refers to a zero or positive eigenvalue, choose it for an index satisfying that condition.
The vectors \(u_i\) with \(\sigma_i\gt0\) are orthonormal and span the image of \(A\), because every output \(Ax=\sum_i\sigma_i(v_i^Tx)u_i\) is a combination of them. So the rank of \(A\) equals the number of positive singular values.
Calculate with the factors
Choose a problem and enter a number, or open its hints. The cases below use three parts of the decomposition. The singular values describe lengths and area, the matching pairs of vectors describe patterns, and the positive singular values tell you which directions can be recovered.
How truncation and the pseudoinverse work
Write the matrix as a sum over its positive singular values. With \(r\) denoting its rank and \(u_i,v_i\) the matching unit vectors,
\[A=\sum_{i=1}^{r}\sigma_i u_iv_i^T.\]Each outer product \(u_iv_i^T\) takes a dot product with \(v_i\) and sends that scalar along \(u_i\). Keeping the first \(k\) terms gives \(A_k\), whose rank is at most \(k\). Because the outer products are mutually orthonormal under the sum of entrywise products, the squared Frobenius error is the sum of the squares of the discarded singular values. For a real matrix and \(0\le k\le r\), the Eckart–Young theorem says this gives the smallest Frobenius error among matrices of rank at most \(k\).
When the target output vector is \(b\), its coordinates in the output basis are \(u_i^Tb\). For each positive \(\sigma_i\), divide that coordinate by \(\sigma_i\) to recover an input coordinate. The component of \(b\) orthogonal to the image cannot be reached and is left as a residual. Any remaining input coordinate lies in a direction that maps to zero. Setting it to zero makes the input as short as possible among least-squares minimizers.
The linear map taking \(b\) to that shortest input is the pseudoinverse \(A^+=V\Sigma^+U^T\). The rectangular diagonal \(\Sigma^+\) has the reversed dimensions of \(\Sigma\), with reciprocals in the positive positions and zeros elsewhere. Small positive singular values amplify changes in the corresponding output coordinates when you divide by them. For an invertible square matrix, the ratio of the largest to the smallest singular value is its condition number in the Euclidean norm. It compares the strongest and weakest stretches.
Further reading
- G. Strang, Introduction to Linear Algebra, 5th ed., chapter 7, The Singular Value Decomposition.
- C. Eckart and G. Young, The Approximation of One Matrix by Another of Lower Rank, Psychometrika (1936).