On this page
If you have ever solved three equations in three unknowns by elimination, you have already done most of an LU decomposition. You just threw away the useful part: the numbers you multiplied rows by. LU decomposition keeps them, and that turns one long calculation into a reusable tool.
What is LU decomposition of a matrix?
An LU decomposition writes a square matrix A as A = LU, where L is lower triangular (zeros above the diagonal) and U is upper triangular (zeros below it), as the Wikipedia article on LU decomposition defines it. In the common version, called Doolittle's form, L has 1s on its diagonal and stores the elimination multipliers, while U is the matrix elimination leaves behind.
The same article notes that the Polish astronomer Tadeusz Banachiewicz introduced the LU decomposition algorithm for general matrices in 1938, and that computers usually solve square linear systems this way. Gilbert Strang's MIT lecture Factorization into A = LU is a good follow-up to the example below.
How do you find L and U? A 3×3 worked example
Take A with rows (2, 1, 1), (4, 3, 3) and (8, 7, 9). Eliminate below the diagonal, column by column, and write down every multiplier.
Row 2 minus 2 × Row 1 gives (0, 1, 1). Multiplier: 2.
Row 3 minus 4 × Row 1 gives (0, 3, 5). Multiplier: 4.
New Row 3 minus 3 × new Row 2 gives (0, 0, 2). Multiplier: 3.
What is left is U, with rows (2, 1, 1), (0, 1, 1) and (0, 0, 2). Its diagonal entries 2, 1 and 2 are the pivots.
Now put each multiplier in L at the position it cleared: 2 goes in row 2, column 1; 4 in row 3, column 1; 3 in row 3, column 2. With 1s on the diagonal, L has rows (1, 0, 0), (2, 1, 0) and (4, 3, 1).
Check one row by multiplying. Row 3 of LU is 4 × (2, 1, 1) + 3 × (0, 1, 1) + 1 × (0, 0, 2) = (8, 7, 9), which is row 3 of A.
How do you solve Ax = b using L and U?
Since A = LU, the equation Ax = b becomes L(Ux) = b. Call Ux = y and solve in two easy passes, as the Wikipedia article's section on solving linear equations describes: first Ly = b, then Ux = y.
Let b = (3, 7, 19).
Forward substitution, Ly = b, top to bottom:
y₁ = 3
2y₁ + y₂ = 7, so y₂ = 1
4y₁ + 3y₂ + y₃ = 19, so y₃ = 4
Back substitution, Ux = y, bottom to top:
2x₃ = 4, so x₃ = 2
x₂ + x₃ = 1, so x₂ = −1
2x₁ + x₂ + x₃ = 3, so x₁ = 1
So x = (1, −1, 2). Put it back into the original equations to confirm: 2 − 1 + 2 = 3, 4 − 3 + 6 = 7 and 8 − 7 + 18 = 19.
Now change the right-hand side to b = (4, 10, 24). You do not touch A again. Forward substitution gives y = (4, 2, 2) and back substitution gives x = (1, 1, 1). That is the whole point: L and U already hold the elimination. If you want more practice setting up systems like this, try these matrices and determinants numerical value questions.
When do you need row swaps (PA = LU)?
Elimination divides by the pivot, so a zero pivot stops it. Take A with rows (0, 2) and (3, 1). It is invertible (its determinant is −6), yet it has no LU decomposition: the Wikipedia article explains that if a₁₁ = 0, then L or U must be singular, which A is not.
The fix is to swap the rows first. A permutation matrix P with rows (0, 1) and (1, 0) does the swap, and PA has rows (3, 1) and (0, 2), which is already upper triangular. So PA = LU with L = I and U = PA. With this partial pivoting, the same source states that every square matrix can be factorized as PA = LU. When you solve, apply the swap to b as well: solve Ly = Pb, then Ux = y.
By hand, you swap only when a pivot is zero. Partial pivoting in software goes further: it picks the entry of largest absolute value in the column as the pivot, because dividing by small numbers magnifies rounding errors.
Why does LU save work for many right-hand sides?
The expensive step is the elimination itself. Computing an LU decomposition of an n × n matrix takes about (2/3)n³ floating-point operations, according to the Wikipedia article on LU decomposition. For n = 1,000 that is roughly 670 million operations.
The two substitutions walk once through each triangle, which is far cheaper for large n. The same article puts it plainly: for many different b, it is faster to decompose A once and solve the triangular systems for each b than to repeat Gaussian elimination. Factorize once, substitute many times. The same elimination also gives you the rank, because U is a row echelon form of A; see how to find the rank of a matrix using row echelon form.
If terms like pivot, triangular matrix or permutation matrix still feel loose, the Fermi Concept Library covers every concept in mathematics, alongside physics, chemistry, biology and computing. And when your own elimination goes wrong at a multiplier, the Fermi Problem Library has a step-by-step solver that explains the reasoning, so you can see exactly which step slipped.



