The QR decomposition factors a matrix
For an
where
A Householder reflector is a symmetric, orthogonal matrix of the form
chosen so that
Applying
The reflectors are stored implicitly: below the diagonal of the working matrix, alongside a
scalar
A Givens rotation
zeros a single sub-diagonal entry by rotating two rows. When one new row streams in after an
existing factorization,
Given the factorization
computed as: (1) multiply
| Case | Time | Space | Notes |
|---|---|---|---|
| Best | Householder on a well-conditioned dense |
||
| Average | Standard flop count from Golub & Van Loan | ||
| Worst | same as average (no pivoting) | Rank-deficient case detected but not re-ordered | |
| Update | Single Givens row update; no re-factor |
All memory is stack-allocated via std::array; the factor is stored in-place over the input.
Factor $A = \begin{pmatrix} 12 & -51 \ 6 & 167 \ -4 & 24 \end{pmatrix}$ (first two columns of the Golub & Van Loan example).
Column 0 (
Column 1 (
The upper-triangular
-
Sign convention: always use
$\sigma = -\mathrm{sign}(x_1)|x|$ to prevent the subtraction$x_1 - \sigma$ from cancelling when$x_1 > 0$ . -
Rank deficiency: a near-zero diagonal entry in
$R$ signals a dependent column; the factorization stops and returns false rather than dividing by zero. -
Accumulating
$Q$ : forming$Q$ explicitly costs an extra$O(mn^2)$ pass and$O(mn)$ storage;ApplyQtransposeavoids this for solves. - Streaming updates: Givens rotations maintain numerical orthogonality one rotation at a time; round-off does not accumulate as severely as re-using a stale Householder factor.
-
Square matrices: thin QR with
$m = n$ still works;$Q$ is$n \times n$ orthogonal.
-
Column pivoting (QRP): permutes columns to move the largest-norm column to the front,
yielding a rank-revealing factorization useful for near-rank-deficient
$A$ . -
Gram-Schmidt (MGS): equivalent in exact arithmetic but numerically inferior; only suitable
when
$A$ is already well-conditioned. -
Block Householder: batches several reflectors into a
$WY$ representation for cache-efficient BLAS-3 level operations on large matrices.
- Overdetermined least-squares regression: calibration curves, polynomial fits, sensor fusion.
- Eigenvalue computation: the QR algorithm iterates
$A_{k+1} = R_k Q_k$ to convergence. - Square-root Kalman filtering: the covariance propagation uses a QR update of the augmented
square-root factor rather than an explicit
$PFP^\top + Q$ product. - Singular Value Decomposition: bidiagonalizes
$A$ via two-sided Householder as a first step.
- Provides the factorization underpinning
SingularValueDecomposition(Golub-Kahan) and the symmetric eigenvalue solver (Jacobi / tridiagonal QR). - The back-substitution step is shared with
GaussianElimination's upper-triangular solve. - Supersedes the normal equations used by
LinearRegressionfor ill-conditioned problems. - The square-root Kalman filter stores
$P^{1/2}$ and updates it with a Givens-based QR update.
- A. S. Householder, "Unitary Triangularization of a Nonsymmetric Matrix," JACM, 5(4), 1958.
- G. H. Golub & C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins UP, 2013, Ch. 5.
- W. H. Press et al., Numerical Recipes in C, 3rd ed., Cambridge UP, 2007, §2.10.