MatrixStep

LU decomposition calculator

Stores the Gaussian elimination multipliers in L and the result in U so that A = LU (or PA = LU).

INPUT

Integers, fractions (1/3) and decimals (0.25) are accepted. Empty cells count as 0. Paste a block of numbers from a spreadsheet or textbook into the first cell to fill the whole matrix.

RESULT

LaTeX is the math code you can paste into Overleaf, Notion equation blocks or Word's equation editor.

What is LU decomposition?

Record the multipliers lᵢⱼ used while reducing A to an upper triangular U in a lower triangular L, and A = LU. This calculator uses the Doolittle form, with 1s on the diagonal of L.

If a pivot is 0, rows must be swapped. Recording the swaps in a permutation matrix P gives PA = LU.

Full explanation with examples: LU Decomposition Step by Step: 3×3 Example and Solving Linear Systems

Exam tipWith LU in hand, Ax = b becomes two substitutions, Ly = b then Ux = y, which is efficient for many right-hand sides.

How to do it by hand

  1. Use Gaussian elimination to reach an upper triangular U, using only 'subtract a multiple of a higher row from a lower row', no row swaps.
  2. Record each multiplier in L at the matching position. If you did R₂ ← R₂ − 3R₁, entry (2,1) of L is 3. The diagonal of L is all 1s.
  3. When elimination finishes, A = LU. Multiply to check.
  4. If a zero pivot forced a row swap, record the swaps in a permutation matrix P and you get PA = LU instead.
  5. To solve Ax = b: solve Ly = b top-down (forward substitution), then Ux = y bottom-up (back substitution).
Worked example

Decompose A = [2 1; 6 4].

R₂ − 3R₁ → U = [2 1; 0 1]. The multiplier was 3, so L = [1 0; 3 1]

Check: LU = [1·2 1·1; 3·2+1·0 3·1+1·1] = [2 1; 6 4] = A ✓

Solve Ax = (4, 10): Ly = b → y = (4, 10−12) = (4, −2); Ux = y → x₂ = −2, 2x₁ + (−2) = 4 → x₁ = 3. So x = (3, −2).

Where is it used?

  • This is how computers actually solve linear systems; it is roughly three times faster than forming the inverse.
  • When the same A is solved for many right-hand sides (simulations, finite element analysis), factor once and only repeat the substitutions.
  • The determinant falls out for free: det(A) = product of the diagonal of U (with a sign adjustment for row swaps).

Common mistakes

  • Recording the multiplier with the wrong sign in L. After R₂ − 3R₁, L₂₁ = +3. L adds back what elimination subtracted.
  • Swapping rows during elimination without recording P. Then LU ≠ A.
  • Putting the pivots on the diagonal of L. In this (Doolittle) factorization L has 1s on its diagonal and the pivots live in U.

How to use

  1. Set the matrix size with the row and column buttons. Up to 6×6 is supported.
  2. Type numbers into the cells and the result updates instantly. Enter fractions as 1/3 and negatives as -2.
  3. Enter moves to the next cell; the ← → ↑ ↓ arrow keys move between cells.
  4. Open ‘Steps’ to see the full working. ‘Copy LaTeX’ copies the result as math code you can paste into Overleaf, a Notion equation block or Word's equation editor.

FAQ

Why does it show PA = LU?
A pivot was 0 during elimination, so rows were swapped. P is the permutation matrix for those swaps, and L, U factor PA.
Can I get det(A) from LU?
Yes: det(A) = ±(product of the diagonal of U), with a minus sign for an odd number of row swaps.
Does a singular matrix have an LU factorization?
Yes. The last diagonal entry of U comes out 0, which means det(A) = 0.

Related guides