SVD of a 2x2 Matrix
Compute the singular value decomposition of a small matrix from its symmetric products and verify the reconstruction.
Problem
The singular value decomposition factors any matrix A into U S V', with U and V orthogonal and S diagonal with non-negative singular values. It reveals how A stretches space: V' rotates, S scales along axes, U rotates again. We compute it for a 2x2 matrix by hand-style steps.
Method
The right singular vectors V are eigenvectors of A'A, the singular values are square roots of its eigenvalues, and the left singular vectors follow from U = A V / sigma. We verify by reassembling A.
import numpy as np
A=np.array([[3.,0.],[4.,5.]])
ATA=A.T@A
vals,V=np.linalg.eigh(ATA)
idx=np.argsort(vals)[::-1]; vals=vals[idx]; V=V[:,idx]
sig=np.sqrt(vals)
U=A@V/sig
print('singular values',np.round(sig,3))
recon=U@np.diag(sig)@V.T
print('reconstruction ok',np.allclose(recon,A))
Result
The two singular values are the axis lengths of the ellipse that A maps the unit circle onto; their ratio is the 2-norm condition number, which measures how much A can amplify errors. Reassembling U S V' recovers A exactly. The largest singular value equals the matrix 2-norm, and the smallest tells you how close A is to singular.
- Singular values are always real and non-negative, even for non-symmetric or rectangular matrices.
- The SVD gives the best low-rank approximation by truncating small singular values (Eckart-Young).
- SVD underlies PCA, POD, and pseudo-inverse least squares throughout Kronos data pipelines.