🧮
🧮 Math & statistics

LU Decomposition Calculator (P·A = L·U with partial pivoting)

Results update as you type.

Your numbers

Understanding the LU decomposition calculator — concept and principle

This calculator factors a square matrix as P·A = L·U with partial pivoting: L is lower triangular with ones on the diagonal, U is upper triangular, and P records the row swaps. It also counts the swaps and gives the determinant. Use it for numerical linear algebra, solving several systems with the same matrix, and checking Gaussian elimination by hand.

LU decompositionP · A = L · UP010100001L1001/210−1/211U4−60041001swap rows 1 and 2 so the pivot is 4 (largest)det A = (−1)¹ × 4 × 4 × 1 = −16
L stores the multipliers used to eliminate; U is what remains; P records row swaps.

How it is calculated

  1. In each column k, swap rows so the pivot is the entry with the largest absolute value (partial pivoting); record the swap in P.
  2. Eliminate the entries below the pivot; each multiplier l_ik = u_ik ÷ u_kk is stored in L.
  3. What remains is the upper-triangular U.

det(A) = (−1)^(number of swaps) × (product of the diagonal of U)

The principle

Gaussian elimination turns A into an upper-triangular matrix by subtracting multiples of rows. Recording those multiples in L lets you undo the elimination: L·U rebuilds A (with rows in the order P). Once L and U are known, solving A x = b takes only two quick triangular substitutions, so the expensive elimination is done once for many right-hand sides. Pivoting on the largest entry keeps all multipliers at most 1 in size, which limits rounding errors.

Worked example

Default input: A = [2 1 1; 4 −6 0; −2 7 2], partial pivoting.

  1. Column 1: the largest entry is 4 (row 2), so swap rows 1 and 2: P = [0 1 0; 1 0 0; 0 0 1], 1 row swap.
  2. Multipliers: row 2 gets 2/4 = 1/2, row 3 gets −2/4 = −1/2; after elimination the second pivot is 4.
  3. Column 2: multiplier 4/4 = 1; the last pivot is 1.
  4. L = [1 0 0; 1/2 1 0; −1/2 1 1], U = [4 −6 0; 0 4 1; 0 0 1].
  5. det(A) = (−1)¹ × 4 × 4 × 1 = −16.

How to read the result

The diagonal of U holds the pivots; a zero pivot means the matrix is singular. Multiplying L·U should give A with its rows in the order given by P. The number of row swaps only affects the sign of the determinant.

Common mistakes

Keep in mind: Results are rounded for display. For large or ill-conditioned matrices, use a numerical library and check the residual.

Frequently asked questions

What is LU decomposition used for?

Solving linear systems efficiently, computing determinants and inverses.

Why use partial pivoting?

To avoid dividing by zero or tiny pivots, which keeps rounding errors small.

How do I get the determinant from LU?

Multiply the diagonal of U and change the sign once for every row swap.

Sources: J. Demmel, UC Berkeley Math 221 lecture notes, Lecture 5 (2020), Gaussian elimination with partial pivoting

Checked 9 Nov 2026. J. Demmel, UC Berkeley Math 221 lecture notes, Lecture 5 (Fall 2020): A = P·L·U with P a permutation, L unit lower triangular (L(i,i) = 1) and U upper triangular; Gaussian elimination with partial pivoting permutes rows so the pivot is the largest entry in absolute value in its column, which gives |L(i,j)| ≤ 1.

🧮 All math & statistics tools →🌍 Calculators by country →