Connect via MCP →

Enter Calculation

Enter the entries of the square matrix row by row. Unused cells (beyond size n) are ignored.

Formula

Formula: LU Decomposition Calculator with Partial Pivoting
Show calculation steps (1)
  1. Determinant

    Determinant: LU Decomposition Calculator with Partial Pivoting

    Determinant from the permutation sign and the product of U's diagonal entries.

Advertisement

Results

Determinant det(A) = sign(P) × product of U diagonal
-16

Lower triangular matrix L

1 0 0
0.5 1 0
-0.5 1 1

Upper triangular matrix U

4 -6 0
0 4 1
0 0 1

Row pivot vector P (0-based)

P = ( 1, 0, 2 )

Because of partial pivoting, L·U equals the row-permuted matrix A (reorder A's rows by P first), so P·A = L·U. A naive L·U product will not reproduce the original A unless you apply the permutation P.

Method Doolittle LU with partial (row) pivoting
Matrix size 3 x 3

What is LU Decomposition with Partial Pivoting?

LU decomposition factors a square matrix A into a lower-triangular matrix L (with 1's on its diagonal) and an upper-triangular matrix U. With partial (row) pivoting we also produce a row-permutation vector P so that \(P \cdot A = L \cdot U\). Pivoting swaps the row with the largest pivot magnitude into place, which avoids dividing by zero and greatly improves numerical stability. This is pure linear algebra and applies identically everywhere.

Diagram showing matrix P times A equals L times U with L lower triangular and U upper triangular
Partial pivoting factors a permuted matrix P·A into a lower-triangular L and an upper-triangular U.

How to use the calculator

Pick the matrix size n (2 to 5), type the entries of your square matrix row by row, and choose how many significant digits to display. Press calculate to get L, U, the pivot vector P (0-based), and the determinant. Cells beyond the chosen size are ignored.

The algorithm

For each column k, find the row p (p ≥ k) maximizing |M[p][k]|, swap it into row k, then for every row i below k compute the multiplier factor = M[i][k] / M[k][k], store it in the lower part, and update the remaining entries M[i][j] -= factor · M[k][j]. After all columns, L is the strictly-lower part of M with unit diagonal and U is the upper part including the diagonal. The determinant equals the sign of the permutation times the product of U's diagonal:

$$\det(A) = \operatorname{sign}(P) \prod_{i} U_{ii}$$
Advertisement
Flow diagram of partial pivoting selecting the largest absolute pivot in a column and swapping rows
Each step selects the row with the largest absolute value in the pivot column and swaps it to the top before eliminating below.

Worked example

For A = [[2,1,1],[4,-6,0],[-2,7,2]], the first pivot is row 1 (|4| is largest), so P becomes (1,0,2). Elimination gives L = [[1,0,0],[0.5,1,0],[-0.5,1,1]], U = [[4,-6,0],[0,4,1],[0,0,1]]. One swap means sign -1, so

$$\det(A) = -1 \times (4 \cdot 4 \cdot 1) = -16$$

FAQ

Why does L·U not equal my original A? Because of pivoting, \(L \cdot U\) equals A with its rows reordered by P. Reorder A's rows by P first, then \(L \cdot U\) matches.

What if my matrix is singular? A zero appears on U's diagonal and the determinant is 0; the factorization is still reported.

Is the pivot vector 0-based? Yes. P[i] is the index of the original row of A that ended up in row i.

Last updated: