Math & Statistics

LU, QR & Cholesky

Comparing LU, QR, and Cholesky matrix factorizations for solving linear systems and optimizing ML algorithms.

🔴 advanced5 min readlinear-algebra
Matrix Decompositions factorize complex matrices into products of simpler canonical matrices (triangular, orthogonal, or diagonal). LU Decomposition factors A = L U (Lower and Upper triangular) for fast linear system solving. QR Decomposition factors A = Q R (Orthogonal Q and Upper triangular R) for stable Gram-Schmidt orthogonalization and least-squares. Cholesky Decomposition factors symmetric positive-definite matrices A = L L^T, running 2x faster than LU for Gaussian processes and covariance modeling.

Why Factorize Matrices?

Directly solving Ax=bA x = b or computing matrix inverse A−1A^{-1} is slow (O(n3)O(n^3)) and numerically unstable on computers due to floating-point rounding errors.

Matrix Decompositions break AA into structured pieces (Triangular, Orthogonal, Diagonal) where solving systems takes simple O(n2)O(n^2) substitution!

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│  1. LU DECOMPOSITION     │  2. QR DECOMPOSITION     │ 3. CHOLESKY DECOMPOSITION│
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ A = L U                  │ A = Q R                  │ A = L L^T                │
│ L: Lower Triangular      │ Q: Orthogonal (Q^T Q = I)│ L: Lower Triangular      │
│ U: Upper Triangular      │ R: Upper Triangular      │ Requires: Symmetric      │
│ General square matrices  │ Numerically stable OLS   │ Positive Definite (Cov)  │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

1. LU Decomposition (A = L U)

Factorizes a general square matrix AA into Lower Triangular LL and Upper Triangular UU:

  Matrix A               Lower L                Upper U
  ┌───┬───┐              ┌───┬───┐              ┌───┬───┐
  │ 2 │ 4 │        =     │ 1 │ 0 │        ×     │ 2 │ 4 │
  ├───┼───┤              ├───┼───┤              ├───┼───┤
  │ 3 │ 8 │              │1.5│ 1 │              │ 0 │ 2 │
  └───┴───┘              └───┴───┘              └───┴───┘

Solving Ax=bA x = b in Two Fast Steps

  1. Forward substitution: Solve Ly=bL y = b for yy (O(n2)O(n^2)).
  2. Back substitution: Solve Ux=yU x = y for xx (O(n2)O(n^2)).

Total solve time drops from O(n3)O(n^3) to O(n2)O(n^2) for multiple right-hand sides bb!

2. QR Decomposition (A = Q R)

Factorizes any m×nm \times n matrix AA into Orthogonal QQ (QTQ=IQ^T Q = I) and Upper Triangular RR:

Numerically Stable Least Squares

To solve Xw=yX w = y:

  1. Factorize X=QRX = Q R.
  2. Substitute into normal equation:

R w = Q^T y

Because RR is upper triangular, solve for weights ww via back-substitution without ever computing XTXX^T X directly! This prevents squaring the matrix condition number.

3. Cholesky Decomposition (A = L L^T)

Applies strictly to Symmetric Positive-Definite matrices (e.g. Covariance matrices Σ\Sigma, Kernel matrices KK):

A = L L^T

Say this out loud

Matrix decompositions turn hard matrix problems into fast triangular solves. LU factors general square matrices into Lower and Upper triangular pieces. QR factors matrices into Orthogonal Q and Triangular R, offering numerically stable least-squares solving without computing X^T X. Cholesky factors symmetric positive-definite matrices like covariance matrices into L L^T twice as fast as LU.

Follow-ups to expect

Check yourself

Question 1 of 3

Why is Cholesky Decomposition (A = L L^T) preferred over LU Decomposition for symmetric positive-definite matrices?

More in Math & Statistics

See all →
Bayes’ Theorem4 minCentral Limit Theorem4 minLaw of Large Numbers4 min