LU Decomposition
Splitting a matrix into a lower-triangular and upper-triangular piece — turning one hard system of equations into two easy ones, and the standard way computers actually solve Ax=b.
Prerequisites: Matrix Inverses and Linear Systems, Determinants
Solving by literally computing is the way to think about it, but real numerical code almost never does that — it's wasteful and less stable. Instead, computers split into two simpler triangular pieces and solve two easy triangular systems in sequence. LU decomposition is that split, and it's the standard machinery quietly running behind almost every "solve this linear system" call in scientific computing.
An analogy: undoing a knot by tracking each step
Solving a general system all at once is like untangling a big knot in one motion — hard to see how. LU decomposition is like methodically recording, one crossing at a time, exactly how the knot was tied (that's the "L," lower-triangular, recording each elimination step) and what shape is left after all the tying (that's the "U," upper-triangular, the simplified end result). Once you have both records, undoing the whole knot for a new starting pull is fast: replay the L record forward, then unwind the U record backward — each in one simple pass, no more searching.
The mathematics, one symbol at a time
LU decomposition factors a square matrix as
where is lower-triangular (all entries above the diagonal are zero, with 1s on the diagonal) and is upper-triangular (all entries below the diagonal are zero). In words: records the row-elimination steps used to reduce to the simplified triangular form — exactly the steps you'd do by hand doing Gaussian elimination, just kept track of and reusable. To solve , substitute: . Let , first solve for (easy: triangular systems solve top-to-bottom by simple substitution, no elimination needed), then solve for (easy again: triangular, bottom-to-top). Two easy triangular solves replace one hard general solve — and once and are computed, solving for many different right-hand sides is cheap, since the expensive factorization step only needs to be done once.
Worked example 1: factoring a 2×2 matrix by hand
Let . Eliminate the first column below the pivot: the multiplier is ; subtract 1.5 times row 1 from row 2: new row 2 is . So and (the multiplier recorded below the diagonal). Check: ✓.
Worked example 2: solving with the factorization, two right-hand sides
Solve with . First : , . Then : ; . So . Now a second right-hand side arrives, — no need to refactor at all: gives , ; gives , . Reusing the same made the second solve nearly free — exactly why LU is the standard choice when the same matrix (say, a fixed hedge structure) is solved against many different target vectors over time.
What this means in practice
LU decomposition is what's actually running under the hood of numpy.linalg.solve and virtually every production linear-solve routine, and it's also how determinants are computed efficiently in practice — , and triangular matrix determinants are just the product of their diagonal entries. Any repeated-solve scenario (recomputing hedge weights against a fixed factor structure but changing target exposures daily) benefits from factoring once and reusing repeatedly.
LU decomposition writes as a lower-triangular times an upper-triangular matrix, turning one hard system into two easy triangular solves; the expensive factorization step is done once and reused cheaply for any number of different right-hand sides.
Plain LU decomposition can fail or become numerically unstable if a pivot (a diagonal entry used as a divisor during elimination) is zero or very small, even when itself is perfectly well-behaved and invertible — the fix used in practice is "LU with partial pivoting," which reorders rows to always divide by the largest available pivot. Don't assume a library's plain LU call is safe on an arbitrary matrix without pivoting; nearly every real implementation includes it by default, but it's worth knowing it's there and why.
Related concepts
Practice in interviews
Further reading
- Golub & Van Loan, Matrix Computations, ch. 3
- Trefethen & Bau, Numerical Linear Algebra, lecture 20