Factor a square matrix into lower and upper triangular matrices with partial pivoting.
LU decomposition factors a square matrix A into P·A = L·U where L is lower triangular with ones on the diagonal, U is upper triangular, and P is a permutation matrix representing row swaps for numerical stability. It is the foundation for efficiently solving linear systems, computing determinants, and finding inverses.
LU Factorisation
P·A = L·U
Determinant
det(A) = (−1)^s × ∏ Uᵢᵢ
At each elimination step, the row with the largest absolute value in the current column is swapped to the pivot position. This prevents division by small numbers and improves numerical accuracy.
With partial pivoting it fails only when the matrix is truly singular (has a zero row in U). For non-singular matrices it always succeeds.