On this page
QR decomposition splits a matrix into a length-preserving part and a triangular part. That split is what lets a computer fit data and find eigenvalues without rounding errors piling up.
What is QR decomposition?
A QR decomposition writes a matrix as A = QR, where Q has orthonormal columns and R is upper triangular (Wikipedia: QR decomposition). Orthonormal means every column of Q has length 1 and is perpendicular to the others, so QᵀQ = I. Upper triangular means every entry below the diagonal of R is zero.
The method in this post is due to Alston Householder, who published it in 1958 as "Unitary Triangularization of a Nonsymmetric Matrix" in the Journal of the ACM.
How does a Householder reflection zero out a column?
A Householder reflection is a mirror. For a vector v, the matrix H = I − 2vvᵀ/(vᵀv) reflects every vector across the plane perpendicular to v. H is orthogonal, so it never changes a length.
To clear a column x below its first entry, you want H to send x to a multiple of e₁ = (1, 0, 0). Since lengths are kept, Hx must be ±‖x‖e₁:
Compute the length ‖x‖.
Set α = −‖x‖ if the first entry of x is positive, and α = +‖x‖ otherwise. The opposite sign makes v a sum rather than a difference of two nearly equal numbers.
Set v = x − αe₁.
Then Hx = αe₁: every entry below the first is zero.
Repeat on the smaller block that remains, one column at a time. After n reflections, Hₙ…H₂H₁A = R, so Q = H₁H₂…Hₙ.
Worked example: QR of a 3×2 matrix by hand
Take the matrix A with rows (2, 2), (1, 6) and (2, 7).
Step 1, first column. x = (2, 1, 2), so ‖x‖ = 3. The first entry is positive, so α = −3 and v = (5, 1, 2), with vᵀv = 30. Then H₁ = I − vvᵀ/15, and H₁A has rows (−3, −8), (0, 4) and (0, 3).
Step 2, second column. Work only below row 1: x = (4, 3), so ‖x‖ = 5, α = −5 and v = (9, 3). The 2×2 mirror I − 2vvᵀ/90 has rows (−4/5, −3/5) and (−3/5, 4/5), and it sends (4, 3) to (−5, 0). Put it in the bottom-right of a 3×3 identity to get H₂.
Result. R has rows (−3, −8), (0, −5) and (0, 0). Q = H₁H₂ has columns q₁ = (−2/3, −1/3, −2/3), q₂ = (2/3, −2/3, −1/3) and q₃ = (−1/3, −2/3, 2/3).
The negative diagonal comes from the sign choice; flip a row of R and the matching column of Q if you want it positive. To practise, factor the matrix with rows (1, 1), (2, 3) and (2, 5) the same way; R's top-left entry should come out as −3. If a step goes wrong, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.
Why is Householder more stable than Gram–Schmidt?
Gram–Schmidt builds Q by subtracting projections from each column in turn. On a computer, the vectors it produces "are often not quite orthogonal, due to rounding errors", and for classical Gram–Schmidt this loss is bad enough that the process is called numerically unstable (Wikipedia: Gram–Schmidt process). The same page notes that algorithms using Householder transformations are more stable than even stabilised Gram–Schmidt.
One way to see why: when two columns point in almost the same direction, Gram–Schmidt subtracts two nearly equal vectors, and what is left is largely rounding error. Householder never forms that difference; every step applies an orthogonal matrix, which keeps lengths.
How is QR used for least squares and eigenvalues?
Least squares. When Ax = b has more equations than unknowns, you look for the x that makes the error ‖Ax − b‖ as small as possible, and QR is often used to solve this (Wikipedia: QR decomposition). Because Q keeps lengths, minimising ‖Ax − b‖ is the same as minimising ‖Rx − Qᵀb‖.
With b = (1, 2, 4) in our example, Qᵀb = (−4, −2, 1). Back substitution on the top two rows gives −5x₂ = −2, so x₂ = 2/5, then −3x₁ − 8(2/5) = −4, so x₁ = 4/15. The leftover entry, 1, is the length of the smallest possible error, and no matrix was inverted.
Eigenvalues. The QR algorithm was developed in the late 1950s by John Francis and Vera Kublanovskaya, working independently (Wikipedia: QR algorithm); Francis's first paper appeared in The Computer Journal in 1961. Factor Aₖ = QₖRₖ, then multiply in reverse, Aₖ₊₁ = RₖQₖ. Every Aₖ is similar to A, so it has the same eigenvalues, and under certain conditions the Aₖ converge to a triangular matrix with the eigenvalues on its diagonal.
If orthogonality or eigenvalues still feel shaky, the Fermi Concept Library gives every concept in mathematics its own lesson and its place in the map, so you can fill the gap first.



