The singular value decomposition (SVD) factors any
For
where
The Golub–Kahan bidiagonalization below runs on a tall matrix. A wide
The singular values satisfy
The Moore-Penrose pseudo-inverse is
for a threshold
The condition number
| Phase | Time | Space | Notes |
|---|---|---|---|
| Bidiagonalization | Two-sided Householder reflectors | ||
| QR sweeps |
|
Golub-Reinsch implicit-shift; converges fast | |
| Pseudo-inverse | Matrix triple product |
||
| Total | Dominated by bidiagonalization |
Here
All storage is stack-allocated; no heap is used. The bidiagonal form is stored implicitly in
the working copy of
Input: $A = \begin{pmatrix} 3 & 0 & 0 \ 0 & -1 & 0 \ 0 & 0 & 2 \end{pmatrix}$ (diagonal matrix).
Phase 1 — Bidiagonalization:
Phase 2 — QR sweeps: The superdiagonal is already zero, so the sweep loop exits immediately.
Sign correction and sort:
-
Rank deficiency: a singular value of exactly zero is harmless; the pseudo-inverse
threshold
$\tau$ must be chosen relative to$\sigma_1$ and machine epsilon to avoid false zero-detection. -
Ill-conditioning in the shift: the implicit shift
$\mu$ is derived from the trailing$2 \times 2$ submatrix; a zero superdiagonal entry deflates the problem before the shift is computed, preventing division by zero. -
Sign ambiguity: singular vectors are defined up to sign; the implementation folds negative
diagonal entries into the sign of the corresponding
$U$ column so that all$\sigma_i \geq 0$ . - Repeated singular values: the corresponding singular-vector subspaces are correct but the individual vectors are not unique; tests should check subspace properties, not individual vectors.
-
Condition number with zero
$\sigma_{\min}$ : a rank-deficient matrix has$\sigma_k = 0$ ;ConditionNumber()returns zero as a sentinel in this case rather than dividing by zero.
-
Full SVD:
$U \in \mathbb{R}^{m \times m}$ and$V \in \mathbb{R}^{n \times n}$ ; the extra columns span the left and right null spaces of$A$ . The thin SVD suffices for least squares; a null-space projector$I - V V^\top$ needs only the thin$V$ . -
Truncated SVD: retain only the
$k$ largest singular values for low-rank approximation$A \approx U_k \Sigma_k V_k^\top$ ; the approximation error in Frobenius norm equals$\sqrt{\sigma_{k+1}^2 + \cdots + \sigma_n^2}$ (Eckart-Young theorem). -
Divide-and-conquer SVD: splits the bidiagonal matrix recursively;
$O(n^2)$ per level and$O(n \log n)$ overall, faster than Golub-Reinsch for large$n$ but incompatible with a no-recursion embedded requirement. -
Jacobi SVD: applies one-sided plane rotations directly to
$A$ ; simpler but$O(n^3)$ per sweep with slower convergence than implicit-shift QR.
-
Least-squares regression:
$x = A^+ b$ minimises$|Ax - b|_2$ and is unique among minimum-norm solutions when$A$ is rank-deficient. For a wide, full-row-rank$A$ (an underdetermined system) it is the minimum-norm exact solution$A^\top (A A^\top)^{-1} b$ . - Control allocation: maps actuator space to output space; the pseudo-inverse distributes effort across redundant actuators while respecting the null space.
- System identification: SVD of a Hankel matrix (Ho-Kalman) recovers system order (rank) and state-space realization from impulse-response data.
- Principal-component analysis (offline): left singular vectors of the centred data matrix are the principal components; singular values are the standard deviations along each axis.
-
Condition monitoring: a rising condition number
$\kappa$ before solving warns that the system is near-singular and the solution may be unreliable.
-
QrDecompositionprovides the Householder reflectors reused in the bidiagonalization phase. -
JacobiEigenSolver(symmetric eigenproblem) is an alternative route to the same result via$\sigma_i^2 = \lambda_i(A^\top A)$ ; the two cross-check each other. -
LuDecompositionandGaussianEliminationsolve square systems but cannot handle rank-deficient or overdetermined cases; SVD supersedes them for those inputs. -
TotalLeastSquares(item 44) builds directly on SVD: the solution lies in the right singular vector corresponding to the smallest singular value of the augmented matrix$[A\ b]$ .
- G. Golub and W. Kahan, "Calculating the Singular Values and Pseudo-Inverse of a Matrix," SIAM J. Numer. Anal., 2(2), 1965.
- G. Golub and C. Reinsch, "Singular Value Decomposition and Least Squares Solutions," Numer. Math., 14(5), 1970.
- G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins UP, 2013, Ch. 6 & 8.
- W. H. Press et al., Numerical Recipes in C, 3rd ed., Cambridge UP, 2007, §2.6.