Before this lesson:lesson 06 (the spectral
theorem), lesson 07(A⊤A is PSD)
and lesson 02 (the four subspaces).
Time: about 95 minutes, plus the notebook.
The spectral theorem only works for symmetric matrices. The SVD works for every matrix,
of every shape. It gives the rank in floating point, orthonormal bases for all four
subspaces, the best low-rank approximation, the pseudoinverse and the nearest orthogonal
matrix. In ML it is behind low-rank compression, PCA (lesson 09), the spectral norm of a
layer and the condition number σmax/σmin (lesson 13). In science, the SVD of a space–time data
matrix is called POD (proper orthogonal decomposition) in fluid dynamics and EOF analysis
(empirical orthogonal functions) in climate science.
Start with a diagonal matrix, A=diag(3,−2). It stretches the x1-axis by 3,
and it stretches the x2-axis by 2 and flips it. The SVD separates the stretch from the
flip: the singular values are 3 and 2 (always ≥0), and the sign goes into an
orthogonal factor.
Now take any 2×2 matrix A. It maps the unit circle to an ellipse. Call the
semi-axes of the ellipse σ1u1 and σ2u2, with orthogonal unit vectors
u1,u2 and σ1≥σ2≥0. The unit vectors v1,v2 that land on these
axes are also orthogonal. So an orthonormal input basis goes to an orthogonal output set:
Avi=σiui.
Put the vi as columns of V and the ui as columns of U. Then AV=UΣ, so
A=UΣV⊤. Read it from right to left:
V⊤ writes the input in coordinates along the vi.
Σ stretches coordinate i by σi. If A is not square, Σ also changes the
dimension from n to m.
U places the result along the ui.
U and V are orthogonal, so each is a rotation or a reflection. For square A with
detA<0, at least one of them must contain a reflection, because
detA=detU⋅detΣ⋅detV and detΣ≥0.
Interactive figure: loading…
Press Play, or step through the three factors.V⊤ turns the orangev1 and the bluev2 onto the axes, Σ stretches the axes by
σ1 and σ2, and U turns the ellipse into place: it ends on the dashed
violet ellipse {Ax:∥x∥=1}. Try diag(3, −2) and det < 0: the
letter F comes out mirrored. The figure puts the mirror into U (it could also go into V),
never into Σ. With rank 1 the circle is flattened to a segment.
The claim "some orthonormal pair v1,v2 has orthogonal images" is the heart of the SVD. Here
is why it is true for every 2×2 matrix, step by step.
Turn a pair. Every orthonormal pair can be written as v1=(cost,sint) and
v2=(−sint,cost) for an angle t, up to the sign of v2.
Measure the angle of the images. Let f(t)=(Av1)⋅(Av2)=v1⊤A⊤Av2.
The images are orthogonal exactly when f(t)=0.
Turn by 90°. Then v1 becomes v2, and v2 becomes −v1. So
f(t+90°)=(Av2)⋅(−Av1)=−f(t): the sign of f flips.
So f has a zero.f is a continuous function of t. It changes sign between t and
t+90°, so it is zero somewhere in between (intermediate value theorem).
What the zero means.f(t)=0 says that A⊤Av1 has no component along v2. In the
plane, that leaves only the direction v1:A⊤Av1=λ1v1. So v1, and in the
same way v2, is an eigenvector of the symmetric matrix A⊤A.
Largest and smallest stretch. Since dtdv1=v2, we get
dtd∥Av1∥2=2v2⊤A⊤Av1=2f(t). So f=0 exactly where ∥Av1∥
is largest or smallest. These extreme lengths are σ1 and σ2.
In n dimensions the same search is the spectral theorem for A⊤A
(lesson 06). The proof in section 3 uses it directly.
Interactive figure: loading…
Turn the pair with the slider, or drag the tip of v1. The magenta number is the angle between
Av1 and Av2. Find the turn where it is 90°, then
press Find the orthogonal images to check. Notice in the lower chart: at that same turn,
∥Av1∥ reaches its maximum σ1 (or its minimum σ2). For the shear the answer is
t≈58.3°, not the eigenvector (1,0) of A. Try 2 × rotation: every pair works, because
A⊤A=4I.
Quick check
You turn the orthonormal pair until Av1⊥Av2. Which statement is now true?
Why.
(Av1)⋅(Av2)=v1⊤A⊤Av2=0 means A⊤Av1 has no v2 part, so A⊤Av1=λv1. Eigenvectors of A are a different thing: the shear has only one eigenvector direction, (1,0), but its orthogonal pair is at t≈58.3°. The pair exists for every matrix, symmetric or not; the lengths are σ1=σ2 in general.
The same factorization is a sum of rank-1 layers, sorted by importance:
Full SVD:A=UΣV⊤ with U∈Rm×m and V∈Rn×n
orthogonal, and Σ∈Rm×n zero except for the diagonal
σ1≥⋯≥σp≥0. Exactly r of the σi are positive.
Thin (reduced) SVD (NumPy's full_matrices=False): keep
p columns of U and V and the p×p block of Σ.
Compact (rank-r) SVD: keep only r columns: A=UrΣrVr⊤ with
Ur∈Rm×r,Σr∈Rr×r,Vr∈Rn×r.
The singular valuesσi are unique. The left singular vectorsui and the
right singular vectorsvi are unique only up to sign (for distinct nonzero
σi), and a sign flip of ui needs the same flip of vi.
Column by column: Avi=σiui and A⊤ui=σivi.
The four subspaces (lesson 02) get orthonormal bases: u1,…,ur span C(A);ur+1,…,um span N(A⊤);v1,…,vr span C(A⊤);vr+1,…,vn span N(A).
Norms: ∥A∥2=σ1 and ∥A∥F=σ12+⋯+σr2, because
orthogonal factors do not change these norms.
The three shapes for one example. Take m=4,n=3 and rank r=2, so p=3 and
σ3=0.
Form
U
Σ
V
What is dropped
full
4×4
4×3
3×3
nothing
thin
4×3
3×3, diagonal (σ1,σ2,0)
3×3
u4, which only meets a zero row of Σ
compact
4×2
2×2
3×2
also u3,v3, which only meet σ3=0
All three give the same product A. The dropped columns are multiplied by zeros of Σ, so
they do not change the product. They are still useful: u3,u4 span N(A⊤) and v3 spans
N(A).
Quick check
A is 4×3 with rank 2. What is the shape of U in the thin SVD (full_matrices=False)?
Why.
The thin SVD keeps p=min(m,n)=3 columns of U, whatever the rank. 4×4 is the full U, and 4×2 is the compact (rank-r)U.U always has m=4 rows, because its columns live in the output space R4.
A⊤A is symmetric and PSD: x⊤A⊤Ax=∥Ax∥2≥0 (lesson 07).
Spectral theorem: A⊤A=VΛV⊤ with V orthogonal and
λ1≥⋯≥λn≥0. Since N(A⊤A)=N(A), exactly r eigenvalues are positive.
For i≤r, set σi=λi and ui=Avi/σi.
The ui are orthonormal:
ui⊤uj=vi⊤A⊤Avj/(σiσj)=λjvi⊤vj/(σiσj)=δij.
For i>r:∥Avi∥2=λi=0, so Avi=0.
Extend u1,…,ur to an orthonormal basis u1,…,um of Rm (the new
vectors span N(A⊤)).
Now AV=UΣ column by column (Avi=σiui for i≤r,Avi=0 for
i>r). Multiply by V⊤ on the right: A=UΣV⊤.■
Steps 5 and 6 on a small example. Take the rank-1 matrix
A=110110(m=3,n=2,r=1).
A⊤A=(2222) has eigenvalues 4 and 0, with
v1=(1,1)/2 and v2=(1,−1)/2.
Step 3: σ1=2 and u1=Av1/2=(2,2,0)/2=(1,1,0)/2.
Step 5: Av2=(0,0,0). There is no σ2>0 to divide by, so step 3 cannot give u2.
Step 6: N(A⊤) is the set of y with y1+y2=0, a plane. Pick any orthonormal basis
of it, for example u2=(1,−1,0)/2 and u3=(0,0,1). Both are orthogonal to u1.
Result: U=[u1u2u3],Σ=200000,V=[v1v2], and UΣV⊤=2u1v1⊤=A.
The choice in step 6 is not unique: any orthonormal basis of the plane N(A⊤) works. It does
not matter, because u2 and u3 meet only zeros of Σ.
Two consequences. First, A⊤A=VΣ⊤ΣV⊤ and AA⊤=UΣΣ⊤U⊤ have
the same nonzero eigenvalues σi2. Second, step 3 is the safe way to pair U with
V. If you eigendecompose AA⊤ separately, each ui comes with an arbitrary sign (or
an arbitrary basis of a repeated eigenspace), and then UΣV⊤=A.
In floating point, do not compute the SVD from A⊤A. Forming it squares the condition
number, and singular values below about εσ1≈10−8σ1
drown in rounding error (section 5). Library SVDs work on A directly (lesson 14).
Why this is true, in words (n=3,k=1). Let B have rank 1. We show that B misses
A by at least σ2 somewhere.
B has rank 1, so by rank–nullity its null space N(B) has dimension 3−1=2: a plane.
W=span(v1,v2) is also a plane. On W,A stretches every unit vector by at
least σ2.
Two planes through 0 in R3 always share a line, because 2+2>3. Take a unit
vector z on that line.
Bz=0, so (A−B)z=Az, and ∥Az∥≥σ2 because z∈W.
This is the same dimension-counting idea as Courant–Fischer in
lesson 06, which has a figure of two planes that share
a line. The general proof replaces "plane" by the right dimensions.
Proof (spectral norm).
A−Ak=∑i>kσiuivi⊤ is itself an SVD, with largest singular value
σk+1. So ∥A−Ak∥2=σk+1.
Let rankB≤k. By rank–nullity, dimN(B)≥n−k.
W=span(v1,…,vk+1) has dimension k+1. Since
(n−k)+(k+1)>n, the two subspaces share a unit vector z∈N(B)∩W.
(A−B)z=Az=∑i≤k+1σi(vi⊤z)ui, so
∥(A−B)z∥2=∑i≤k+1σi2(vi⊤z)2≥σk+12∑i≤k+1(vi⊤z)2=σk+12.
Hence ∥A−B∥2≥∥(A−B)z∥≥σk+1.■
Proof of the Frobenius case (uses Weyl's inequality for singular values)
This proof uses one result that this track does not prove in full: Weyl's inequality for
singular values,
σi+j−1(X+Y)≤σi(X)+σj(Y)(i,j≥1,i+j−1≤min(m,n)).
See Horn and Johnson, Topics in Matrix Analysis (Cambridge University Press, 1991), Theorem 3.3.16.
The special case j=1 gives ∣σk(A+E)−σk(A)∣≤∥E∥2, which
lesson 17 proves.
Let rankB≤k. Then σk+1(B)=0.
Use Weyl with X=A−B,Y=B and j=k+1. Since X+Y=A:σi+k(A)≤σi(A−B)+σk+1(B)=σi(A−B).
Square and sum over i=1,…,p−k:∑i>kσi(A)2≤∑i≤p−kσi(A−B)2≤∥A−B∥F2.
The left side is ∥A−Ak∥F2.■
Reading the formulas. The relative Frobenius error is
∑i>kσi2/∑iσi2: the root of the fraction of "energy" that you
drop. For an error budget, pick the smallest k that meets it.
Other norms, and when the best approximation is unique
Mirsky extended the theorem to every unitarily invariant norm (a norm with
∥Q1AQ2∥=∥A∥ for orthogonal Q1,Q2). For example, in the nuclear norm
∥A∥∗=∑iσi the error of Ak is σk+1+⋯+σr, and it is again
optimal.
The Frobenius minimizer is unique when σk>σk+1. The spectral-norm minimizer is
usually not unique. A simple case: for A=diag(3,1) and k=1, both
diag(3,0) and diag(3.5,0) have rank 1 and spectral error
∥A−B∥2=1=σ2.
Interactive figure: loading…
Move the rank slider. The middle image is Ak, the sum of the first k layers
σiuivi⊤. The chart shows the singular values you keep, the grey
ones you drop, and the relative error, which is exactly
∑i>kσi2/∑iσi2. Switch to axis-aligned blocks: a background and three
rectangles need only rank 4, and the error drops to rounding level. The rotated square has the same
kind of content but needs far more terms, because its edges are not aligned with the rows and
columns. Set the third panel to k-th layer to see single rank-1 terms.
Quick check
A has singular values 5,3,2,1. What is ∥A−A2∥F, the Frobenius error of the best rank-2 approximation?
Why.
The Frobenius error is the root of the sum of all dropped σi2:22+12=5. The value 2=σ3 is the error in the spectral norm. 3 would be the error if you kept only one layer, in the spectral norm.
For m>n, use the thin SVD; then Q is m×n with orthonormal columns.
Meaning.P is symmetric PSD: it stretches by σi along the orthogonal axes
vi.Q is orthogonal: it rotates or reflects. This is the matrix version of
z=eiθ∣z∣ for a complex number.
Uniqueness.P is always unique (the PSD square root of A⊤A is unique). If A is
invertible, Q=AP−1 is unique too.
Rotation or not. For invertible square A,detQ=sign(detA). So Q is a
rotation only when detA>0. Example: the swap A=(0110) has
P=I and Q=A, a reflection. In the same way, U and V in the SVD are orthogonal, not
always rotations (lesson 04 explains the
difference).
Nearest orthogonal matrix.Q=UV⊤ minimizes ∥A−W∥F over all orthogonal W.
Why UV⊤ is the nearest orthogonal matrix
For orthogonal W,∥W∥F2=n. Expand: ∥A−W∥F2=∥A∥F2+n−2tr(W⊤A).
So minimizing the distance means maximizing tr(W⊤A).
Insert the SVD: tr(W⊤A)=tr(W⊤UΣV⊤)=tr(V⊤W⊤UΣ)=tr(ZΣ),
with Z=V⊤W⊤U (the trace does not change under cyclic shifts).
Z is a product of orthogonal matrices, so it is orthogonal and every entry has ∣zii∣≤1.
tr(ZΣ)=∑iziiσi≤∑iσi, with equality at Z=I,
that is, W=UV⊤.■
Interactive figure: loading…
The same factors, read as A=QP.P=VΣV⊤ stretches along v1 and v2 without
turning them; then Q=UV⊤ moves the ellipse into place. Here detA<0, so Q is a
reflection: the F is mirrored. Pick shear or symmetric to get a rotation instead.
where Σ+(n×m) has 1/σi for each nonzero σi and zeros everywhere
else. This is the (Moore–Penrose) pseudoinverse. A+ undoes A from the column space back to
the row space, and it sends N(A⊤) to zero:
AA+=UrUr⊤ is the orthogonal projector onto C(A);
A+A=VrVr⊤ is the orthogonal projector onto C(A⊤).
Special cases: A+=(A⊤A)−1A⊤ for full column rank, A+=A⊤(AA⊤)−1 for full
row rank, and A+=A−1 for invertible A.
Theorem.x+=A+b minimizes ∥Ax−b∥2, and among all minimizers it has the
smallest ∥x∥2. It is the minimum-norm least-squares solution.
Proof. Let c=U⊤b and y=V⊤x. Orthogonal maps keep 2-norms, so ∥x∥=∥y∥.
The second sum does not depend on x. The first sum is zero exactly when
yi=ci/σi for i≤r; the yi with i>r are free. These are all the
least-squares solutions.
∥x∥2=∥y∥2=∑i≤r(ci/σi)2+∑i>ryi2 is smallest when the free
yi are 0.
That y is Σ+c, so x=VΣ+U⊤b=A+b.■
Geometrically, Ax+ is the projection of b onto C(A), and x+ lies in the row space.
Any other solution is x++w with w∈N(A), and w⊥x+, so
∥x++w∥2=∥x+∥2+∥w∥2.
Numerics.A+ is not a continuous function of A:diag(1,ε)+=diag(1,1/ε) blows up as ε→0,
but diag(1,0)+=diag(1,0). So libraries treat
σi≤rcond⋅σ1 as zero. The number of singular values above this cut-off
is the numerical rank. This truncation is a form of regularization, like ridge.
Interactive figure: loading…
Two planes: the input space of x and the output space of b. With σ2=0 the
matrix has rank 1. Drag b:Ax+ is its projection onto the line C(A), and the dashed
magenta residual is perpendicular to it. In the input space, every point of the
thick violet line is a least-squares solution; x+ is the one in the row
space, closest to 0. Drag x along the line and compare ∥x∥. Then raise σ2 a little
(0.05): A becomes invertible and x+ jumps far away. Switch on the cut-off: σ2≤0.1σ1
is treated as 0, as rcond does, and x+ stays small at the price of a nonzero residual.
Quick check
What is the pseudoinverse of A=diag(2,0)?
Why.
Invert the nonzero singular value and keep the zero: Σ+=diag(1/2,0), and here U=V=I. Every matrix has a pseudoinverse. The formula (A⊤A)−1A⊤ needs full column rank; here A⊤A=diag(4,0) has no inverse.
Answers to section 1. (1) No. A⊤A=(1112) has eigenvalues
(3±5)/2, so σ=(5±1)/2≈1.618,0.618. Eigenvalues describe
directions that stay on their own line; singular values describe stretching. The
products agree: σ1σ2=∣detA∣=1. (2) By Eckart–Young,
12+0.12=1.01≈1.005.
SVD.A⊤A=(3113) has eigenvalues 4 and 2, with
eigenvectors v1=(1,1)/2 and v2=(1,−1)/2. So σ1=2,σ2=2.
u1=Av1/σ1=(2,2,0)/(22)=(1,1,0)/2.
u2=Av2/σ2=(0,0,2)/(2⋅2)=(0,0,1).
For the full SVD, u3=(1,−1,0)/2 spans N(A⊤) (check: A⊤u3=0).
Quick check
For this A, what is the spectral norm ∥A∥2?
Why.
∥A∥2=σ1=2, the largest stretch of a unit vector. 6=σ12+σ22 is the Frobenius norm. 4 is the largest eigenvalue of A⊤A, that is σ12: you must take the square root. 2=σ2 is the smallest stretch.
Best rank-1 approximation.A1=σ1u1v1⊤=110110 and
A−A1=00100−1. Both errors are 2=σ2, as the
theorem says (only one singular value is discarded, so the two norms agree).
Polar.Q=u1v1⊤+u2v2⊤=1/21/21/21/21/2−1/2
(orthonormal columns) and
P=2v1v1⊤+2v2v2⊤=(1+211−211−211+21).
Check: P2=(3113)=A⊤A and QP=A.
Pseudoinverse and least squares.A+=21v1u1⊤+21v2u2⊤=(1/41/41/41/41/2−1/2),
the same as (A⊤A)−1A⊤ (full column rank). For b=(2,4,1):x+=A+b=(2,1),Ax+=(3,3,1), and the residual b−Ax+=(−1,1,0) is a multiple of u3, so it is
orthogonal to C(A). ✓
Minimum norm. Now solve with the rank-1 matrix A1. Its pseudoinverse is
A1+=21v1u1⊤=41(111100), and A1+b=(3/2,3/2).
Since A1x=(x1+x2)(1,1,0) and the best fit of (2,4) by one number is 3, every
x with x1+x2=3 is a least-squares solution. The pseudoinverse picks the one in the
row space span{(1,1)}, which has the smallest norm.
The libraries check the hand computations. The notebook builds each of these from the SVD
(and the SVD itself from eigh).
importnumpyasnpfromscipy.linalgimportpolarA=np.array([[1.,1.],[1.,1.],[1.,-1.]])U,s,Vt=np.linalg.svd(A)# full SVD: U (3, 3), s (2,), Vt (2, 2)print(s)# [2. 1.41421356]print(np.linalg.svd(A,full_matrices=False).U.shape)# thin U: (3, 2)A1=np.array([[1.,1.],[1.,1.],[0.,0.]])# rank-1 answer of section 4print(np.linalg.norm(A-A1,2),np.linalg.norm(A-A1,"fro"))# both 1.414...Q,P=polar(A)# A = Q Pprint(Q.round(4))# [[0.5 0.5] [0.5 0.5] [0.7071 -0.7071]]print(P.round(4))# [[1.7071 0.2929] [0.2929 1.7071]]b=np.array([2.,4.,1.])print(np.linalg.pinv(A)@b)# [2. 1.]print(np.linalg.pinv(A1)@b)# [1.5 1.5]: the minimum-norm solutionprint(np.linalg.lstsq(A1,b,rcond=None)[0])# the sameprint(np.linalg.svd(np.array([[1.,1.],[0.,1.]]),compute_uv=False))# [1.618 0.618]# Why not the SVD from eig(AᵀA): a 50 x 2 matrix with σ = 1 and 1e-12rng=np.random.default_rng(0)Qa,_=np.linalg.qr(rng.standard_normal((50,2)))Qb,_=np.linalg.qr(rng.standard_normal((2,2)))B=Qa@np.diag([1.0,1e-12])@Qb.Tprint(np.linalg.svd(B,compute_uv=False)[1])# 1.0000084e-12: correct to about ε·σ₁print(np.sqrt(abs(np.linalg.eigvalsh(B.T@B)[0])))# 1.077e-09: rounding noise
np.linalg.svd never forms A⊤A. It calls LAPACK's gesdd: Householder
bidiagonalization of A, then a divide-and-conquer SVD of the bidiagonal matrix (lesson 14).
The QR-iteration driver is gesvd; SciPy offers it as
scipy.linalg.svd(..., lapack_driver="gesvd").
Low-rank compression with an error budget. A weight matrix W∈Rm×n
stored as UkΣkVk⊤ needs k(m+n+1) numbers instead of mn, with Frobenius
error exactly ∑i>kσi2, and no matrix of rank ≤k does better.
LoRA (lesson 15) also restricts an update to rank ≤r.
POD and EOFs in science. Stack snapshots of a flow or a climate field as columns.
The left singular vectors are the spatial modes, σi2 is the energy of mode i, and
truncation gives the basis of a reduced-order model or a surrogate. PCA (lesson 09) is
the same on centered data.
Least squares and inverse problems.np.linalg.lstsq uses the SVD and returns the
minimum-norm solution for collinear features. Truncated SVD and ridge damp the small
σi that amplify noise in ill-posed problems (deblurring, tomography).
Orthogonalization. Orthogonal Procrustes (aligning molecules, point clouds or
embeddings): the orthogonal W that minimizes ∥WX−Y∥F is UV⊤ from the SVD of
YX⊤. The Muon optimizer (2024) replaces each momentum matrix by an approximation of
its polar factor UV⊤, computed with a Newton–Schulz iteration.
Spectral norm.σ1(W) is the Lipschitz constant of x↦Wx. Spectral
normalization divides W by an estimate of σ1 from power iteration.
Getting U and V from two separate eigendecompositions. The signs (or the bases of
repeated eigenspaces) do not match. Use ui=Avi/σi.
Treating singular values as $|eigenvalues|$. They agree only for normal matrices
(A⊤A=AA⊤, for example symmetric or orthogonal). The shear has eigenvalues
1,1 and singular values 1.618,0.618.
"U and V are rotations." They are orthogonal. A reflection is allowed, and it is
forced when detA<0.
Shapes. The full U is m×m, the thin one m×p, the compact one
m×r. NumPy returns V⊤ (Vt), not V.
The wrong Eckart–Young error. The spectral error is the single number σk+1;
the Frobenius error is the root of the sum of all discarded σi2.
Inverting tiny singular values.1/σ for σ≈10−14 multiplies noise by
1014. Truncate with rcond.
Writing A+=(A⊤A)−1A⊤ for every A. It needs full column rank, and even
then it is numerically worse than the SVD.
A symmetric matrix has eigenvalues 3 and −2. What are its singular values, and how are ui and vi related?Answer3 and 2.u1=v1 for λ=3 and u2=−v2 for λ=−2:σi=∣λi∣, and the sign goes into U.
A is 1000×500 with rank 50. Give the shapes of the factors of the full SVD and of the rank-r SVD, and the storage of the rank-50 form.AnswerFull: U1000×1000,Σ1000×500,V500×500. Rank-r:1000×50,50×50,500×50. Storage: 50(1000+500+1)=75,050 numbers instead of 500,000.
The singular values are 6,3,2,1. What is the smallest k with a relative Frobenius error of at most 20%? What is the spectral error then?Answer∥A∥F2=50.k=2:5/50≈0.316, too big. k=3:1/50≈0.141. So k=3, with spectral error σ4=1 (relative 1/6).
Compute the pseudoinverse of a nonzero column vector a∈Rm and interpret a+b.AnswerThe SVD is a=(a/∥a∥)∥a∥(1), so a+=a⊤/∥a∥2.a+b=a⊤b/∥a∥2 is the coefficient of the projection of b onto the line through a.
Find the polar decomposition of A=(01−20). Is Q a rotation?AnswerA⊤A=diag(1,4), so P=diag(1,2) and Q=AP−1=(01−10), a rotation by 90° (consistent with detA=2>0).
Why does the spectral-norm proof of Eckart–Young use k+1 right singular vectors, not k?AnswerTo force an intersection with N(B):dimN(B)≥n−k and (n−k)+(k+1)>n. On span(v1,…,vk+1),A stretches every unit vector by at least σk+1.
Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
State the SVD of an m×n matrix A.
A=UΣV⊤ with U(m×m) and V(n×n) orthogonal and Σ(m×n) diagonal with σ1≥⋯≥0. Column by column, Avi=σiui.
How are the singular values of A related to A⊤A?
σi=λi(A⊤A), and the right singular vectors vi are the eigenvectors of A⊤A.
You know vi and σi>0. How do you get ui, and why not from a separate eigendecomposition of AA⊤?
ui=Avi/σi. A separate eigendecomposition gives each ui an arbitrary sign, so UΣV⊤ may not equal A.
Why does every 2×2 matrix have an orthonormal pair v1,v2 with Av1⊥Av2?
f(t)=(Av1)⋅(Av2) changes sign when the pair turns by 90°, so it is zero at some angle. There v1,v2 are eigenvectors of A⊤A.
Eckart–Young in the spectral norm: what is the smallest ∥A−B∥2 over rankB≤k?
σk+1, reached by the truncated SVD Ak=∑i≤kσiuivi⊤.
Eckart–Young in the Frobenius norm: what is the smallest ∥A−B∥F over rankB≤k?
σk+12+⋯+σr2, reached by the same Ak.
A has singular values 4,2,1. What are the best rank-1 errors in the spectral and the Frobenius norm?
Spectral: σ2=2. Frobenius: 22+12=5≈2.24.
How do you get the polar decomposition A=QP from the SVD?
Q=UV⊤ (orthogonal, the nearest orthogonal matrix to A) and P=VΣV⊤=(A⊤A)1/2 (symmetric PSD).
Write the pseudoinverse with the SVD. What is special about A+b?
A+=VΣ+U⊤=∑i≤rσi−1viui⊤.A+b minimizes ∥Ax−b∥2 and, among all minimizers, has the smallest ∥x∥2.
Why should you not compute the SVD from eig(AᵀA) in floating point?
Forming A⊤A squares the condition number, so singular values below about εσ1≈10−8σ1 are lost in rounding.
"Explain the SVD in one sentence." — Every matrix maps some orthonormal basis vi to
orthogonal vectors σiui: rotate or reflect, stretch, rotate or reflect.
"How do singular values relate to eigenvalues?" — σi2 are the eigenvalues of
A⊤A. For symmetric A,σi=∣λi∣. For square A in general,
maxi∣λi∣≤σ1 and ∏i∣λi∣=∏iσi=∣detA∣.
"How would you compress a layer to a given error?" — Compute the SVD, choose the smallest
k with ∑i>kσi2 within the budget, and store k(m+n+1) numbers.
Eckart–Young says this is optimal for that rank.
"Why not compute the SVD with eig(AᵀA)?" — It squares the condition number, so small
singular values drown in rounding error.
The notebook for this lesson runs in Colab. It has four exercises, each with a check
cell and a folded solution:
svd_via_eig: build the thin SVD from np.linalg.eigh(A.T @ A) and ui=Avi/σi, the
existence proof as code; see where it fails for a tiny singular value.
truncated_svd and eckart_young_error on a generated image: compare the measured errors
with σk+1 and ∑i>kσi2, and find the smallest k for a 5% budget.
polar: Q=UV⊤,P=VΣV⊤; check that Q is the nearest orthogonal matrix and
use it to undo a rotation of a point cloud (orthogonal Procrustes).
pinv: the pseudoinverse with an rcond cut-off; check the minimum-norm property on a
rank-deficient least-squares problem.
Open on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press play