LU Decomposition Calculator with Step-by-Step Matrices

Factor a square matrix using partial pivoting, then inspect P, L, U, every elimination step, and the reconstruction check. Inputs stay in your browser.

Enter a Square Matrix

Enter integers, decimals, or scientific notation. The displayed precision does not round intermediate calculations.

Separate columns with spaces, commas, or tabs and rows with new lines. A pasted 2×2 through 8×8 square matrix changes the selected size.

LU Factors

Enter a valid matrix to calculate P·A = L·U.

P

L

U

det(A)
Row swaps
Relative max error

Advertisement

Step-by-Step LU Working

At pivot column k, partial pivoting chooses the largest available absolute entry. Each lower row then uses mᵢₖ = Uᵢₖ / Uₖₖ and Rᵢ ← Rᵢ − mᵢₖRₖ.

Decompose a valid matrix to see every pivot and elimination stage.

LU Decomposition Formula and Convention

This calculator uses a Doolittle-style factorization with partial row pivoting. L has ones on its diagonal, U is upper triangular, and P records the row order.

Factorization

P A = L U

If no row swaps are needed, P is the identity matrix and this reduces to A = LU.

Elimination multiplier

mᵢₖ = Uᵢₖ / Uₖₖ

The multiplier is stored in Lᵢₖ while the corresponding entry below the pivot is eliminated from U.

Determinant

det(A) = (−1)ˢ ∏ Uᵢᵢ

Here s is the number of row swaps. The diagonal product of unit-lower-triangular L is 1.

Numerical convention: The calculator treats a pivot as zero when it is tiny relative to the largest input entry and machine precision. Calculations use JavaScript double-precision floating-point arithmetic; decimal-place selection changes display only.

How to Use the LU Decomposition Calculator

  1. Choose the matrix dimension, then fill every cell of square matrix A. You can also paste an entire matrix.
  2. Select Decompose matrix. The calculator uses partial pivoting and displays the relation P·A = L·U.
  3. Read down the working to see the chosen pivot, any row swap, each multiplier, and the updated factors.
  4. Use the determinant and reconstruction error to check the result, then copy the summary or download the matrices as CSV.

Worked 3×3 Example

For A = [[2,1,1],[4,−6,0],[−2,7,2]], the first pivot is 4, so rows 1 and 2 are swapped. Partial pivoting then continues with elimination multipliers stored below the diagonal in L. The final factors satisfy P·A = L·U, and the determinant is −16.

Why swap rows?

Choosing the largest absolute pivot in the current column avoids division by zero and usually reduces amplification of floating-point rounding.

How to verify the answer

Multiply L and U, then compare the product with the row-permuted matrix P·A. The calculator reports their relative maximum difference.

Common LU Decomposition Mistakes

Comparing LU directly with A

When rows were swapped, the product is LU = PA, not necessarily A. Include the permutation matrix in the check.

Forgetting earlier L entries

When two rows are swapped at a later pivot, the already-computed entries in those rows of L must also be swapped.

Rounding during elimination

Rounding multipliers at each step can noticeably change later pivots. Keep full precision until the final display.

LU Decomposition FAQs

What is LU decomposition?

LU decomposition expresses a square matrix using a lower-triangular factor L and an upper-triangular factor U. It is a reusable form of Gaussian elimination.

Why is there a permutation matrix P?

Partial pivoting may move a stronger pivot into the diagonal position. P records these row swaps, making the calculator’s convention PA = LU.

Can every square matrix be decomposed?

Every nonsingular square matrix has a pivoted LU decomposition. If the matrix is singular to working precision, the calculator stops at the zero pivot and explains why a complete nonsingular factorization was not produced.

How is the determinant calculated?

Multiply the diagonal entries of U and change the sign once for each row swap. Since the diagonal of L consists of ones, det(L) = 1.

What does the reconstruction error tell me?

It compares LU with PA. A value near machine precision indicates that the displayed factorization reconstructs the permuted input closely, although ill-conditioned matrices can still magnify rounding in later uses.

Does LU decomposition solve a linear system by itself?

It supplies the expensive factorization step. To solve Ax=b, apply the same permutation to b, solve Ly=Pb by forward substitution, then solve Ux=y by back substitution.

Are my matrix entries private?

Yes. This page performs parsing, factorization, copying, and CSV generation locally. The tool code does not transmit or store your entries.

Calculation Notes

Last reviewed: August 4, 2026 by the Starlight Tools editorial team.

Inputs must be finite and no larger than 10¹⁰⁰ in magnitude. Matrix size is limited to 8×8 so the complete working remains readable. Extremely ill-conditioned matrices may have meaningful numerical error even when the reconstruction check is small.

Explore more tools