Linear algebra tool

LU Decomposition Calculator

Factor a square matrix into lower and upper triangular matrices using partial pivoting. Calculate P, L and U, find the determinant, and check that PA = LU.

Enter your matrix

Enter one row per line. Separate numbers with spaces, commas or semicolons. Scientific notation such as 1.5e-3 is accepted. Matrices from 2 x 2 through 10 x 10 are supported.

What is LU decomposition?

LU decomposition expresses a square matrix as a product of triangular matrices. With partial pivoting, rows may be reordered to improve numerical stability.

P A = L U

Why is partial pivoting useful?

At each elimination step, the algorithm selects the largest absolute entry in the current pivot column. Swapping that row into position helps avoid division by zero and generally reduces numerical problems caused by small pivots.

How is the determinant calculated?

Each row swap changes the sign of the determinant. The determinant of the upper triangular matrix is the product of its diagonal entries. Therefore, the determinant of A is the product of the diagonal entries of U multiplied by negative one for each odd number of row swaps.

Worked example

Use the default matrix:

A = [2 1 1]
    [4 -6 0]
    [-2 7 2]

Partial pivoting selects the row containing 4 as the first pivot. For this example, the determinant is -16. The verification matrices PA and LU should match up to rounding error.

Frequently asked questions

Does LU decomposition always exist without pivoting?

Not in a useful form for every matrix. A zero pivot can prevent ordinary elimination. Partial pivoting swaps rows to select a better pivot when possible.

Why is the result PA = LU instead of A = LU?

The permutation matrix records the row swaps performed during elimination. When row pivoting is needed, the factorization applies to the reordered matrix PA.

Can a singular matrix have an LU decomposition?

A singular matrix can still have a triangular factorization, although one or more pivots may be zero. A singular matrix does not have a unique solution for every linear system.

What does the factorization error show?

It reports the largest absolute entry-wise difference between PA and LU. A small value indicates that the computed factors reconstruct the permuted input matrix accurately.

Related matrix calculators