LU Decomposition Calculator with Partial Pivoting

LU Decomposition Calculator with Partial Pivoting

Emerging AI Skill PRO

Enter Calculation

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

Formula

PA=LUwhere{A=[aij]n×n,n=Matrix sizeukj=akj−∑m<kℓkmumjℓik=aik−∑m<kℓimumkukkdet⁡A=(−1)s∏k=1nukkP A = L U \\[1.5em] \text{where}\quad \left\{ \begin{aligned} A &= \left[{\htmlData{var=a_{{ i }}_{{ j }}}{\text{a}_{ij}}}\right]_{n \times n},\; n = \text{Matrix size} \\ u_{kj} &= a_{kj} - \sum_{m<k} \ell_{km}\, u_{mj} \\ \ell_{ik} &= \frac{a_{ik} - \sum_{m<k} \ell_{im}\, u_{mk}}{u_{kk}} \\ \det A &= (-1)^{s} \prod_{k=1}^{n} u_{kk} \end{aligned} \right.
Show calculation steps (2)
  1. Partial Pivoting Rule

    p=arg⁡maxk≤r≤n|ark|,Rk↔Rp,mik=aikakk(i>k)for n=Matrix sizep = \arg\max_{k \le r \le n} \left| a_{rk} \right|, \quad R_k \leftrightarrow R_p, \quad m_{ik} = \frac{a_{ik}}{a_{kk}} \;\; (i > k) \quad \text{for } n = \text{Matrix size}

    Row selection at elimination step k: pick the row p at or below k with the largest absolute value in column k, then swap rows k and p and count the swap in s.

  2. Displayed Value Rounding

    x~=round(x·10q)10q,q=Display digits−⌈log10|x|⌉\tilde{x} = \frac{\operatorname{round}\left(x \cdot 10^{\,q}\right)}{10^{\,q}}, \quad q = \text{Display digits} - \left\lceil \log_{10} \left| x \right| \right\rceil

    Every entry of L, U and the determinant is rounded to the selected number of significant digits before display.

Usage stats

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 )
Method Doolittle LU with partial (row) pivoting
Matrix size 3 x 3

Report an error on this page

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:

Most popular in Math and Statistics

View all Math and Statistics calculators