QR Decomposition
QR Decomposition factors any matrix into a product , where has orthonormal columns and is upper triangular. It exists for every real or complex matrix, is the engine behind least-squares solvers and the QR algorithm for eigenvalues, and was developed through the work of Gram, Schmidt, Householder, and Givens in the late 19th and 20th centuries.
Any spanning set of vectors can be replaced by an orthonormal basis built one vector at a time, subtracting off the parts already accounted for. The orthonormal vectors become the columns of ; the coefficients describing how each original column is reconstructed from the orthonormal ones form the upper-triangular . Triangularity is not imposed — it falls out automatically because the -th original column lies in the span of only the first orthonormal vectors.
Formal Statement
Let with . A QR decomposition of is a factorization
Derivation hint: This is the defining equation; its existence is established constructively in the proof below. where the symbols mean:
- — the input matrix whose columns are ;
- — an matrix with orthonormal columns, i.e. (in the reduced / thin form);
- — an upper-triangular matrix, with entries for .
In the full form, is orthogonal () and is upper triangular with zero rows at the bottom:
Derivation hint: Append orthonormal vectors to the columns of the thin to complete an orthonormal basis of ; the extra columns multiply the zero block.
Every admits a QR decomposition. If and has full column rank (), then the thin decomposition is unique under the normalization that the diagonal entries of are positive:
Derivation hint: Uniqueness follows from the uniqueness of Gram–Schmidt with a fixed sign convention, or equivalently from the uniqueness of the Cholesky factor of .
Why It Holds / Derivation
Assume has full column rank with columns .
Step 1. Define the first orthogonal vector and normalize:
Derivation hint: by full rank, so dividing by its norm is valid; .
Step 2. For , subtract the components of along the already-built orthonormal vectors:
Derivation hint: Each term is the orthogonal projection coefficient onto ; removing them leaves for all . Full rank guarantees .
Step 3. By construction is orthonormal, so satisfies . Solving the relations above for gives
with and for . Derivation hint: Rearrange equation [5]; the sum ranges only over , which is exactly the upper-triangular pattern.
Step 4. Collecting these relations into matrix form yields where is upper triangular with positive diagonal. Derivation hint: The -th column of equals , matching equation [6] column-by-column.
∎Suppose with both 's having positive diagonals. Then . The product of upper-triangular matrices is upper triangular, so is upper triangular; but is orthogonal. An orthogonal upper-triangular matrix is diagonal, and a diagonal orthogonal matrix has entries . Positive diagonals of force , hence and . Derivation hint: Key facts — (i) inverse of upper triangular is upper triangular; (ii) an orthogonal matrix whose entries vanish below the diagonal must be diagonal because its columns are unit-length and mutually orthogonal.
∎Erhard Schmidt, a student of David Hilbert, formalized the orthogonalization procedure in 1907 while developing the theory of integral equations and Hilbert spaces — the abstract setting where "orthonormal basis" became a precise concept. Jørgen Pedersen Gram had introduced essentially the same idea in 1883 in the context of least squares. Although neither wrote "," their procedure is the conceptual heart of the decomposition. The numerically robust matrix algorithms (Householder, Givens) arrived only with the computer era in the 1950s–60s.
Building Intuition
Think of the columns of as a skewed, non-perpendicular set of axes. Gram–Schmidt straightens them: points along ; keeps only the part of perpendicular to ; keeps only the part of perpendicular to the plane spanned by ; and so on. The matrix is the "translation dictionary" telling you how to rebuild the original skewed columns from the clean perpendicular ones. Because only ever involves , the dictionary is upper triangular. Multiplying by an orthogonal is a rotation/reflection — it preserves lengths and angles — so QR says: every set of vectors is a rigid rotation of a "stretched-and-sheared" triangular set.
Worked Examples
Given:
Derivation hint: We apply equations [4]–[6] directly.
Step 1 — first column. , so
Derivation hint: .
Step 2 — second column. Projection coefficient:
Derivation hint: Dot product of with .
Derivation hint: Subtract the parallel part; note since their dot product is .
Derivation hint: .
Boxed answer:
Derivation hint: Verify : the entry is , etc. Quantities here are dimensionless.
Given: Fit a line through the data points . The overdetermined system is with
Derivation hint: Each row encodes .
Step 1 — QR of . Column 1: , , . Column 2: . Then
Derivation hint: Subtract the mean (here removes the average value from each entry of ).
Step 2 — transform the right side. The least-squares solution solves :
Derivation hint: Multiply by each orthonormal column.
Step 3 — back-substitution in , with :
Derivation hint: Solve the bottom equation first, substitute upward.
Boxed answer:
Derivation hint: This is the same answer the normal equations give, but obtained more stably. Variables carry the units of and respectively.
Common Misconceptions
The decomposition is not unique without a sign convention. If you negate a column of and the corresponding row of , you get another valid QR. Software packages (LAPACK, NumPy) do not generally return positive diagonal ; comparing your hand result to `numpy.linalg.qr` may show sign flips that are entirely legitimate. Uniqueness in Theorem [3] holds only after fixing .
Classical Gram–Schmidt is numerically dangerous. Although equations [4]–[6] are mathematically exact, in floating point the computed columns of lose orthogonality catastrophically when the columns of are nearly dependent. Never implement classical Gram–Schmidt for serious numerical work — use Modified Gram–Schmidt, Householder reflections, or Givens rotations instead, all of which compute the same but with vastly better stability.
Consider with (a Läuchli-type matrix). Classical Gram–Schmidt computes whose inner product with is of order in floating point — orthogonality instead of . Modified Gram–Schmidt cuts this error to machine precision, and Householder QR delivers orthogonality to full machine precision regardless of conditioning. This is the classic demonstration that the same exact decomposition can be computed well or badly.
Connections
QR sits at the crossroads of several pillars of linear algebra. It is the matrix encoding of Gram-Schmidt Process, and its factor is precisely the Cholesky Decomposition factor of the normal matrix (since ). It is the workhorse of Least Squares Problems, where solving avoids forming the ill-conditioned . Iterated QR is the QR Algorithm for Eigenvalues, the standard method for computing the Eigenvalues and Eigenvectors of dense matrices. It complements the Singular Value Decomposition (rank-revealing but costlier) and the LU Decomposition (for square solves), and the orthogonal embodies Orthogonal Matrices.
Real-World Applications
Historical Development
Subtleties & Limits
Rank-deficiency and rank-revealing QR. When does not have full column rank, the plain QR can place tiny or zero pivots anywhere, masking the true rank. Rank-revealing QR (RRQR) uses column pivoting ( with permutation ) to push the "small" directions to the trailing columns, but no pivoting strategy is provably optimal for all matrices — constructing a strong rank-revealing factorization that is both cheap and guaranteed accurate remains an active area. Relatedly, communication-avoiding QR (TSQR/CAQR) for tall-skinny matrices on parallel hardware trades classical pivoting for blocked orthogonalization, and balancing stability against minimal data movement on modern GPUs/exascale machines is an ongoing engineering and analysis challenge. For the complex case, becomes unitary () and the same theory carries over, but high-performance complex QR with careful rounding analysis still attracts research.
See Also
Gram-Schmidt Process · Cholesky Decomposition · LU Decomposition · Singular Value Decomposition · Orthogonal Matrices · Householder Reflections · Givens Rotations · Least Squares Problems · QR Algorithm for Eigenvalues