Numerical Linear Algebra: LU and QR Decompositions

⚡ Key Takeaways

LU and QR decompositions factor a matrix AA into structured pieces — A=LUA = LU (lower × upper triangular, via Gaussian elimination) or A=QRA = QR (orthogonal × upper triangular, via Gram–Schmidt or Householder reflections). LU solves square linear systems Ax=bAx=b efficiently; QR solves least-squares and underpins eigenvalue algorithms. These are the two workhorse factorizations of numerical linear algebra, used everywhere from circuit simulation to statistics. Formalized in the 20th century (Turing, Householder, Givens) on foundations from Gauss.

💡 The Core Insight

Every elementary row operation is left-multiplication by a simple matrix. LU collects all the elimination steps into one lower-triangular matrix LL; QR replaces "elimination" by "orthogonalization," collecting all the rotations/reflections into an orthogonal QQ. In both cases the right factor RR (or UU) is upper triangular, so the original problem Ax=bAx=b becomes two triangular systems, each solvable in O(n2)O(n^2) by back/forward substitution. Triangularity is the whole game: it is the structure that makes solving cheap.

Formal Statement

DefinitionLU Decomposition

Let A∈Rn×nA \in \mathbb{R}^{n\times n}. An LU decomposition is a factorization

1
A=LU,\quad A = LU,

where LL is unit lower triangular (ℓii=1\ell_{ii}=1, ℓij=0\ell_{ij}=0 for j>ij>i) and UU is upper triangular (uij=0u_{ij}=0 for i>ji>j). The entries below the diagonal of LL are the multipliers used in Gaussian elimination; UU is the row-echelon (upper) result. Derivation hint: count degrees of freedom — AA has n2n^2 entries; LL contributes (n2)\binom{n}{2} free entries, UU contributes (n+12)\binom{n+1}{2}, summing to n2n^2.

DefinitionQR Decomposition

Let A∈Rm×nA \in \mathbb{R}^{m\times n} with m≥nm \ge n. A QR decomposition is

2
A=QR,\quad A = QR,

where Q∈Rm×mQ \in \mathbb{R}^{m\times m} is orthogonal (QTQ=IQ^{\mathsf T}Q = I) and R∈Rm×nR \in \mathbb{R}^{m\times n} is upper triangular. The reduced (thin) QR uses Q^∈Rm×n\hat Q \in \mathbb{R}^{m\times n} with orthonormal columns and R^∈Rn×n\hat R \in \mathbb{R}^{n\times n} upper triangular, so A=Q^R^A = \hat Q \hat R. Derivation hint: apply Gram–Schmidt to the columns a1,…,ana_1,\dots,a_n; the orthonormal outputs form Q^\hat Q, and the projection coefficients fill R^\hat R.

TheoremExistence and Uniqueness

(LU). If all leading principal minors of AA are nonzero, then AA has a unique LU decomposition with LL unit lower triangular. In general (any nonsingular AA), a row permutation exists so that PA=LUPA = LU — the LU with partial pivoting.

(QR). Every A∈Rm×nA \in \mathbb{R}^{m\times n} (m≥nm\ge n) has a QR decomposition. If AA has full column rank, the reduced decomposition A=Q^R^A=\hat Q\hat R is unique once we require the diagonal entries of R^\hat R to be positive.

ProofLU exists when leading minors are nonzero

Proceed by induction / direct elimination.

Step 1. The (1,1)(1,1) leading minor is a11≠0a_{11}\ne 0 (it equals the first principal minor). Define multipliers ℓi1=ai1/a11\ell_{i1}=a_{i1}/a_{11} for i>1i>1. Subtracting ℓi1\ell_{i1} times row 1 from row ii zeros the first column below the diagonal. This is left-multiplication by an elementary lower-triangular matrix M1M_1 with −ℓi1-\ell_{i1} in its first column.

Step 2. The resulting matrix A(2)=M1AA^{(2)}=M_1 A has the same trailing principal minors structure; its (2,2)(2,2) pivot is nonzero exactly because the second leading minor of AA is nonzero (the minor equals a11⋅a_{11}\cdot pivot2_2). Repeat: form M2M_2, then M3M_3, ..., Mn−1M_{n-1}.

Step 3. After n−1n-1 stages,

3
Mn−1⋯M2M1A=U,\quad M_{n-1}\cdots M_2 M_1 A = U,

Derivation hint: each MkM_k clears column kk below the pivot; the product is upper-triangularization.

Step 4. Each MkM_k is unit lower triangular, so its inverse is too, and

4
L=M1−1M2−1⋯Mn−1−1\quad L = M_1^{-1}M_2^{-1}\cdots M_{n-1}^{-1}

Derivation hint: inverse of a product reverses order; each Mk−1M_k^{-1} just flips the sign of its off-diagonal multipliers. is unit lower triangular. A clean miracle: LL's subdiagonal entries are exactly the multipliers ℓik\ell_{ik} (no interaction between stages), so A=LUA = LU.

Step 5 (uniqueness). Suppose L1U1=L2U2L_1U_1=L_2U_2. Then L2−1L1=U2U1−1L_2^{-1}L_1 = U_2 U_1^{-1}. The left side is unit lower triangular, the right is upper triangular; a matrix that is both is the identity. Hence L1=L2, U1=U2L_1=L_2,\ U_1=U_2. ■\blacksquare

∎
ProofQR via Gram–Schmidt

Let a1,…,ana_1,\dots,a_n be the columns of full-rank AA.

Step 1. Set q1=a1/∥a1∥q_1 = a_1/\|a_1\|, with r11=∥a1∥r_{11}=\|a_1\|.

Step 2. For k=2,…,nk=2,\dots,n, subtract projections onto previous qjq_j:

5
vk=ak−∑j=1k−1(qjTak) qj,rjk=qjTak.\quad v_k = a_k - \sum_{j=1}^{k-1} (q_j^{\mathsf T}a_k)\,q_j,\qquad r_{jk}=q_j^{\mathsf T}a_k.

Derivation hint: vkv_k is the component of aka_k orthogonal to span(q1,…,qk−1)\mathrm{span}(q_1,\dots,q_{k-1}).

Step 3. Normalize: qk=vk/∥vk∥q_k = v_k/\|v_k\|, rkk=∥vk∥>0r_{kk}=\|v_k\|>0 (nonzero by full rank).

Step 4. Rearranging, ak=∑j=1krjkqja_k = \sum_{j=1}^{k} r_{jk}q_j, which in matrix form is exactly A=Q^R^A=\hat Q\hat R with R^\hat R upper triangular. Orthonormality gives Q^TQ^=I\hat Q^{\mathsf T}\hat Q=I.

Step 5 (uniqueness). If Q^1R^1=Q^2R^2\hat Q_1\hat R_1 = \hat Q_2\hat R_2 then Q^2TQ^1=R^2R^1−1\hat Q_2^{\mathsf T}\hat Q_1 = \hat R_2\hat R_1^{-1} is both orthogonal and upper triangular with positive diagonal, hence the identity. ■\blacksquare

∎
⚠️ Classical Gram–Schmidt is numerically unstable

The algorithm above (classical Gram–Schmidt, CGS) loses orthogonality catastrophically in finite precision when columns are nearly dependent. In practice use Modified Gram–Schmidt (MGS) — subtract projections one at a time, updating aka_k immediately — or, better, Householder QR. MGS and Householder are mathematically equivalent to CGS but vastly more accurate.

AT
Alan Turing
1912–1954

Turing's 1948 paper "Rounding-off errors in matrix processes" gave the first rigorous error analysis of Gaussian elimination and explicitly framed it as the matrix factorization A=LUA=LU (he wrote it in terms of triangular factors). He introduced the condition number concept for matrices, quantifying how input errors amplify. This reconceptualization — elimination as factorization — is what allowed the subsequent stability theory of Wilkinson and others. Turing thus turned a centuries-old hand computation into an object of modern numerical mathematics.

Building Intuition

🧠 Intuition

Think of solving Ax=bAx=b as undoing a complicated transformation. LU says: AA stretches space in a way that decomposes into a "shear" (LL) followed by an "axis-aligned scaling with shear" (UU). To invert, undo UU then LL — each triangular, each cheap.

QR says: AA's action equals "first rotate/reflect (QQ), then upper-triangular shear (RR)." Because QQ is just a rigid motion (∥Qx∥=∥x∥\|Qx\|=\|x\|), it preserves lengths and angles — it never amplifies error. That is why QR is so stable, and why it shines for least-squares: minimizing ∥Ax−b∥\|Ax-b\| becomes minimizing ∥Rx−QTb∥\|Rx - Q^{\mathsf T}b\|, and a rigid motion of the residual changes nothing.

Figure
LU and QR as compositions of simpler maps
Two factorizations of A acting on a unit square A = L U (shear ∘ shear/scale) I →U→ U·□ →L→ LU·□ = A·□ A = Q R (shear, then rigid rotation) I →R→ R·□ →Q→ QR·□ = A·□ (lengths preserved by Q)

Worked Examples

ExampleLU decomposition and solving a system

Given. Solve Ax=bAx=b with

A=(211433879),b=(51432).A=\begin{pmatrix}2&1&1\\4&3&3\\8&7&9\end{pmatrix},\qquad b=\begin{pmatrix}5\\14\\32\end{pmatrix}.

Step 1 — eliminate column 1. Pivot 22. Multipliers ℓ21=4/2=2\ell_{21}=4/2=2, ℓ31=8/2=4\ell_{31}=8/2=4.

A(2)=(211011035).A^{(2)}=\begin{pmatrix}2&1&1\\0&1&1\\0&3&5\end{pmatrix}.

Step 2 — eliminate column 2. Pivot 11. Multiplier ℓ32=3/1=3\ell_{32}=3/1=3.

U=(211011002),L=(100210431).U=\begin{pmatrix}2&1&1\\0&1&1\\0&0&2\end{pmatrix},\qquad L=\begin{pmatrix}1&0&0\\2&1&0\\4&3&1\end{pmatrix}.

Step 3 — forward solve Ly=bLy=b. y1=5y_1=5;   2(5)+y2=14⇒y2=4\;2(5)+y_2=14\Rightarrow y_2=4;   4(5)+3(4)+y3=32⇒y3=0\;4(5)+3(4)+y_3=32\Rightarrow y_3=0.

Step 4 — back solve Ux=yUx=y. 2x3=0⇒x3=02x_3=0\Rightarrow x_3=0;   x2+x3=4⇒x2=4\;x_2 + x_3 = 4\Rightarrow x_2=4;   2x1+x2+x3=5⇒x1=12\;2x_1+x_2+x_3=5\Rightarrow x_1=\tfrac12.

x=(12,  4,  0)T(dimensionless solution vector)\boxed{x = (\tfrac12,\;4,\;0)^{\mathsf T}}\quad\text{(dimensionless solution vector)}

Check: Ax=(5,14,32)T=b.A x = (5,14,32)^{\mathsf T} = b. ✓

ExampleQR decomposition by Gram–Schmidt

Given.

A=(111001).A=\begin{pmatrix}1&1\\1&0\\0&1\end{pmatrix}.

Step 1. a1=(1,1,0)Ta_1=(1,1,0)^{\mathsf T}, ∥a1∥=2\|a_1\|=\sqrt2, so q1=12(1,1,0)Tq_1=\tfrac1{\sqrt2}(1,1,0)^{\mathsf T} and r11=2r_{11}=\sqrt2.

Step 2. a2=(1,0,1)Ta_2=(1,0,1)^{\mathsf T}. Projection coefficient r12=q1Ta2=12(1)=12r_{12}=q_1^{\mathsf T}a_2 = \tfrac1{\sqrt2}(1)=\tfrac1{\sqrt2}.

v2=a2−r12q1=(1,0,1)T−12(1,1,0)T=(12,−12,1)T.v_2 = a_2 - r_{12}q_1 = (1,0,1)^{\mathsf T} - \tfrac12(1,1,0)^{\mathsf T} = (\tfrac12,-\tfrac12,1)^{\mathsf T}.

Step 3. ∥v2∥=14+14+1=3/2\|v_2\| = \sqrt{\tfrac14+\tfrac14+1}=\sqrt{3/2}, so r22=3/2r_{22}=\sqrt{3/2} and q2=23(12,−12,1)T=16(1,−1,2)T.q_2 = \sqrt{\tfrac{2}{3}}(\tfrac12,-\tfrac12,1)^{\mathsf T} = \tfrac1{\sqrt6}(1,-1,2)^{\mathsf T}.

Result.

Q^=(1/21/61/2−1/602/6),R^=(21/203/2).\hat Q=\begin{pmatrix}1/\sqrt2 & 1/\sqrt6\\[2pt]1/\sqrt2 & -1/\sqrt6\\[2pt]0 & 2/\sqrt6\end{pmatrix},\qquad \hat R=\begin{pmatrix}\sqrt2 & 1/\sqrt2\\[2pt]0 & \sqrt{3/2}\end{pmatrix}.
A=Q^R^,Q^TQ^=I2\boxed{A = \hat Q\hat R,\quad \hat Q^{\mathsf T}\hat Q = I_2}

Check: Q^R^\hat Q\hat R reproduces AA, and the columns of Q^\hat Q are orthonormal. ✓

Common Misconceptions

⚠️ Pivoting is not optional

A nonzero determinant does not guarantee a stable (or even existing) LU without pivoting. The matrix (0111)\begin{pmatrix}0&1\\1&1\end{pmatrix} has no LU factorization at all (its (1,1)(1,1) pivot is 00), yet it is nonsingular. Even when a pivot is merely small, dividing by it amplifies rounding errors. Partial pivoting — swapping in the largest-magnitude entry of the active column as pivot — keeps all multipliers ∣ℓij∣≤1|\ell_{ij}|\le 1 and is the practical default.

CounterexampleWhy classical Gram–Schmidt fails

Take, in 3-digit arithmetic, the near-collinear columns

a1=(1,ε,0)T, a2=(1,0,ε)Ta_1=(1,\varepsilon,0)^{\mathsf T},\ a_2=(1,0,\varepsilon)^{\mathsf T}

with ε=10−3\varepsilon = 10^{-3}. After normalizing a1a_1 and subtracting its projection from a2a_2, the tiny orthogonal component is computed as the difference of two nearly-equal large numbers — catastrophic cancellation destroys it. The resulting q2q_2 can fail to be orthogonal to q1q_1 to working precision. Householder QR avoids this entirely because it never forms such differences; it works with norm-preserving reflections.

Connections

connection

LU is the matrix incarnation of Gaussian Elimination, and its determinant follows instantly: det⁡A=det⁡L⋅det⁡U=∏uii\det A = \det L\cdot\det U = \prod u_{ii}. The symmetric positive-definite specialization is the Cholesky Decomposition A=LLTA=LL^{\mathsf T}, half the cost of LU. QR is built from Orthogonal Projection and the Gram–Schmidt Process, and it is the engine of the QR Algorithm for Eigenvalues and Eigenvectors. Both decompositions are quantitatively governed by the Condition Number, and QR's stability links to the Singular Value Decomposition, the most robust (but costliest) factorization. The least-squares use of QR is the computational core of Linear Regression.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- c. 179 CE — The Chinese Nine Chapters on the Mathematical Art describes elimination-style solution of linear systems.
- 1809–1810 — Gauss systematizes elimination while computing the orbit of Ceres (least squares), giving the method its modern name.
- 1888 — Wilhelm Jordan popularizes the Gauss–Jordan variant.
- 1907 — Erhard Schmidt formalizes the orthogonalization process (with roots in Gram, 1883).
- 1948 — Alan Turing publishes the first rounding-error analysis, framing elimination as the factorization A=LUA=LU and introducing matrix condition numbers.
- 1948 — Alston Householder and others develop systematic matrix-computation theory.
- 1958 — Householder introduces reflection-based QR, the stable standard.
- 1958–1961 — John Francis and Vera Kublanovskaya independently invent the QR algorithm for eigenvalues — one of the top algorithms of the 20th century.
- 1965 — James Wilkinson's The Algebraic Eigenvalue Problem consolidates backward-error analysis of LU and QR.

Subtleties & Limits

open-problem

Even partial pivoting can, in pathological cases, exhibit exponential element growth (the Wilkinson matrix), making LU unstable in principle — yet such matrices essentially never arise in practice, and why average-case growth is benign remains incompletely understood (the subject of "smoothed analysis," Sankar–Spielman–Teng, 2006). For sparse matrices, choosing a pivot order that minimizes fill-in while preserving stability is NP-hard, driving ongoing research in heuristic orderings. Communication cost, not arithmetic, now dominates on modern hardware, spurring "communication-avoiding" LU and QR variants (CALU, TSQR) whose stability–performance trade-offs are still being charted.

See Also

Gaussian Elimination · Cholesky Decomposition · Gram–Schmidt Process · Householder Reflections · Givens Rotations · Singular Value Decomposition · QR Algorithm · Condition Number · Least Squares Problems · Linear Regression