Linear Algebra
4.1314 min read

LU Decomposition and Efficient Solving

LU decomposition factors a matrix as PA=LUPA = LU, where PP is a permutation matrix (from row swaps), LL is unit lower triangular (the elimination multipliers on and below the diagonal), and UU is upper triangular (the echelon form).

Why is this useful? To solve Ax=bA\mathbf{x} = \mathbf{b}: compute  mathbfc=Pb\ mathbf{c} = P\mathbf{b} (apply row permutations, O(n)O(n)), then solve Ly=cL\mathbf{y} = \mathbf{c} by forward substitution (O(n2)O(n^2)), then solve Ux=yU\mathbf{x} = \mathbf{y} by back substitution (O(n2)O(n^2)). Total: O(n2)O(n^2) per right-hand side after O(n3)O(n^3) one-time factorization.

This pays off when solving Ax=b1,Ax=b2,A\mathbf{x} = \mathbf{b}_1, A\mathbf{x} = \mathbf{b}_2, \ldots for many different b\mathbf{b}: factorize once (O(n3)O(n^3)), then solve each system in O(n2)O(n^2). MATLAB's x=A\bx = A \backslash b uses LU under the hood.

Formal View

Theorem 4.13 (LU Decomposition)
Every invertible matrix ARn×nA \in \mathbb{R}^{n \times n} has a factorization PA=LUPA = LU where PP is a permutation matrix, LL is unit lower triangular (diagonal entries all 1), and UU is upper triangular with nonzero diagonal. To solve Ax=bA\mathbf{x} = \mathbf{b}: \begin{enumerate} \item Set c=Pb\mathbf{c} = P\mathbf{b} \item Solve Ly=cL\mathbf{y} = \mathbf{c} (forward substitution) \item Solve Ux=yU\mathbf{x} = \mathbf{y} (back substitution) \end{enumerate}
Remark 4.13 — Complexity
LU decomposition: O(n3)O(n^3) (done once). Forward/back substitution: O(n2)O(n^2) per right-hand side. If kk systems Ax=biA\mathbf{x} = \mathbf{b}_i are solved, total cost is O(n3+kn2)O(n^3 + kn^2) versus O(kn3)O(kn^3) without LU.

Interactive Visualization

LU Decomposition Animator

Why This Matters

LU decomposition is the backbone of practical linear system solving in science and engineering.

  • MATLAB's backslash operator, NumPy's `linalg.solve`, and LAPACK all use LU decomposition
  • Finite element analysis solves the same stiffness matrix AA for many load vectors b\mathbf{b}
  • Real-time simulation in games uses pre-factored LU to solve physics constraints efficiently

Quiz

Question 1

If PA=LUPA = LU, solving Ax=bA\mathbf{x} = \mathbf{b} requires:

Question 2

LU decomposition is most efficient when the same matrix AA is used to solve systems with many different right-hand sides.

Common Mistakes

  • Computing A1A^{-1} explicitly to solve Ax=bA\mathbf{x} = \mathbf{b} — LU decomposition is far more efficient and numerically stable.
  • Forgetting the permutation matrix PP — it records the row swaps needed for numerical stability.
  • Applying LU to singular matrices — LU decomposition requires invertibility for the square case.