About the LU Decomposition Calculator
This LU decomposition calculator factors a square matrix A into a lower-triangular matrix L and an upper-triangular matrix U so that A = LU. Paste a matrix up to 6 × 6 and choose Doolittle (1s on the diagonal of L, the textbook default), Crout (1s on the diagonal of U), or partial pivoting, which adds a permutation matrix P so that PA = LU and works for any square matrix.
Every entry is computed with exact fractions, so you get the same L and U you would find by hand — no 0.333333 rounding — together with the list of row operations (each multiplier ℓᵢⱼ goes straight into L), the number of row swaps and the determinant, which is the product of U’s diagonal with a sign for each swap.
LU factorization is how computers solve systems Ax = b efficiently: factor once, then solve Ly = Pb by forward substitution and Ux = y by back substitution for as many right-hand sides as you like. It is a core topic in linear algebra and numerical methods courses. Without pivoting, the decomposition fails if a zero pivot appears; switch to partial pivoting in that case.
How to use the lu decomposition calculator
- 1Type the square matrix, one row per line, entries separated by spaces or commas.
- 2Choose Doolittle, Crout, or partial pivoting (needed if a zero pivot appears).
- 3Read L, U (and P) and check the determinant.
- 4Follow the row operations table to see where each entry of L comes from.
Formula and method
LU decomposition records Gaussian elimination. To clear the entries below pivot uₖₖ, each row i below it has ℓᵢₖ times row k subtracted; the remaining upper-triangular matrix is U, and the multipliers ℓᵢₖ, placed below a diagonal of 1s, form L (the Doolittle form). Crout’s form moves U’s diagonal into L instead, so U has 1s on its diagonal.
If a pivot is zero (or, numerically, very small), rows must be exchanged. Partial pivoting swaps in the row with the largest absolute entry in the pivot column and records the swaps in a permutation matrix P, giving PA = LU, which exists for every square matrix. All arithmetic here uses exact fractions. The determinant is the product of the pivots, with the sign flipped once per row swap.
- L
- Lower triangular matrix (multipliers)
- U
- Upper triangular matrix (result of elimination)
- P
- Permutation matrix recording row swaps
- ℓᵢₖ
- Multiplier used to clear entry (i, k)
Worked examples
Doolittle LU of a 3 × 3 matrix
Subtract 2·R₁ from R₂ and −1·R₁ from R₃ (ℓ₂₁ = 2, ℓ₃₁ = −1), then −1·R₂ from R₃ (ℓ₃₂ = −1). U has pivots 2, −8 and 1, so det A = 2 × (−8) × 1 = −16.
Same matrix with partial pivoting
The largest entry in column 1 is 4, so R₁ and R₂ swap. Eliminating with ℓ₂₁ = 1/2 and ℓ₃₁ = −1/2 leaves 4 and 4 in column 2 (a tie, so no swap), then ℓ₃₂ = 1. The pivots are 4, 4 and 1 and one swap flips the sign: det A = −(4 × 4 × 1) = −16.
Zero pivot needs pivoting
The (1, 1) entry is 0, so plain A = LU does not exist. Swapping the rows gives an upper-triangular matrix immediately: L = I, U = [[2, 3], [0, 1]], and one swap makes det A = −(2 × 1) = −2.
Crout form of a 2 × 2 matrix
Doolittle gives L = [[1, 0], [3/2, 1]] and U = [[4, 3], [0, −3/2]]. Crout moves U’s diagonal into L: L = [[4, 0], [6, −3/2]], U = [[1, 3/4], [0, 1]]. det A = 4 × (−3/2) = −6.
Frequently asked questions
What is LU decomposition?+
It writes a square matrix as the product of a lower-triangular matrix L and an upper-triangular matrix U, A = LU. It is Gaussian elimination stored in matrix form: U is the eliminated matrix and L holds the multipliers used.
Why is LU decomposition useful?+
Once A = LU is known, solving Ax = b takes two quick triangular solves (forward substitution with L, back substitution with U). That is much cheaper than repeating elimination for each new b, and it also gives the determinant as the product of U’s diagonal.
Does every matrix have an LU decomposition?+
Not without row swaps. If a zero pivot appears during elimination, A = LU fails — for example [[0, 1], [1, 0]]. With partial pivoting, every square matrix has a factorization PA = LU, where P is a permutation matrix.
What is the difference between Doolittle and Crout?+
Both give A = LU. Doolittle puts 1s on the diagonal of L, so U carries the pivots; Crout puts 1s on the diagonal of U, so L carries them. They are related by a diagonal scaling, and the determinant is the same either way.
Why use partial pivoting even when no pivot is zero?+
In floating-point computing, a tiny pivot creates huge multipliers that amplify rounding errors. Choosing the largest available pivot keeps all multipliers at most 1 in size, which is why numerical libraries such as LAPACK use PA = LU by default.