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.
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}$$
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.