Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Find the LU Decomposition

Factor a square matrix as A=LUA = LU: UU is the upper triangular matrix that Gaussian elimination produces, and LL is lower triangular with 11s on the diagonal and the elimination multipliers below it.

Recognize the task

A square matrix and the words LU decomposition or LU factorization, or several systems Ax=bA\mathbf{x} = \mathbf{b} with the same AA and different right-hand sides. Forms: (211433879)\begin{pmatrix} 2 & 1 & 1 \\ 4 & 3 & 3 \\ 8 & 7 & 9 \end{pmatrix}, (4363)\begin{pmatrix} 4 & 3 \\ 6 & 3 \end{pmatrix}. Test: if a zero lands in a pivot position during elimination, you need PA=LUPA = LU.
The factorization is built in the LU decomposition lesson; elimination itself is the Gaussian elimination method.

Two ways to do it

No pivotingall pivots nonzero
A=LU,lij=multiplier used to clear entry (i,j)A = LU, \quad l_{ij} = \text{multiplier used to clear entry } (i, j)
Works when every pivot is nonzero (LU decomposition).
Partial pivotingzero or small pivot
PA=LUPA = LU
Swap rows to bring a nonzero, preferably the largest, entry into the pivot position, and record the swaps in PP (partial pivoting).

Steps

StepOn A=(211433879)A = \begin{pmatrix} 2 & 1 & 1 \\ 4 & 3 & 3 \\ 8 & 7 & 9 \end{pmatrix}
1Check the first pivot. It must be nonzero. If it is zero, swap rows and switch to PA=LUPA = LU.a11=2≠0a_{11} = 2 \neq 0
2Clear column 1 and record the multipliers. The multiplier is li1=ai1/a11l_{i1} = a_{i1}/a_{11}; subtract li1l_{i1} times row 1 from row ii.l21=2l_{21} = 2, l31=4l_{31} = 4: rows 2 and 3 become (0,1,1)(0, 1, 1), (0,3,5)(0, 3, 5)
3Clear column 2 the same way. Use the new pivot in row 2; continue until the matrix is upper triangular.l32=31=3l_{32} = \frac{3}{1} = 3: row 3 becomes (0,0,2)(0, 0, 2)
4Read off U and L. UU is the final matrix. LL has 11s on the diagonal and each multiplier in the position of the zero it created.U=(211011002)U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{pmatrix}, L=(100210431)L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ 4 & 3 & 1 \end{pmatrix}
5Check by multiplying. LULU must give back AA. As a bonus, the determinant is the product of the pivots (determinant via LU).LU=ALU = A ✓, det⁡(A)=2⋅1⋅2=4\det(A) = 2 \cdot 1 \cdot 2 = 4

Worked examples

Example 1 · a two-by-two matrix

one multiplier
A=(4363)A = \begin{pmatrix} 4 & 3 \\ 6 & 3 \end{pmatrix}: l21=64=32l_{21} = \frac{6}{4} = \frac{3}{2}
row 2 minus 32\frac{3}{2} row 1
L=(10321)L = \begin{pmatrix} 1 & 0 \\ \frac{3}{2} & 1 \end{pmatrix}, U=(430−32)U = \begin{pmatrix} 4 & 3 \\ 0 & -\frac{3}{2} \end{pmatrix}
3−32⋅3=−323 - \frac{3}{2} \cdot 3 = -\frac{3}{2}

Example 2 · solving with L and U

two triangular solves
Ax=(4,10,24)A\mathbf{x} = (4, 10, 24) with the factors above
solve Ly=bL\mathbf{y} = \mathbf{b}, then Ux=yU\mathbf{x} = \mathbf{y}
forward: y1=4y_1 = 4, y2=10−2⋅4=2y_2 = 10 - 2 \cdot 4 = 2, y3=24−4⋅4−3⋅2=2y_3 = 24 - 4 \cdot 4 - 3 \cdot 2 = 2
top to bottom
back: x3=1x_3 = 1, x2=2−1=1x_2 = 2 - 1 = 1, x1=4−1−12=1x_1 = \frac{4 - 1 - 1}{2} = 1
bottom to top
x=(1,1,1)\mathbf{x} = (1, 1, 1)
check: Ax=(4,10,24)A\mathbf{x} = (4, 10, 24) ✓
These are the LU solve steps; the second half is back substitution.

Example 3 · a zero pivot

PA = LU
A=(011121279)A = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 2 & 1 \\ 2 & 7 & 9 \end{pmatrix}: a11=0a_{11} = 0, swap rows 1 and 2
record the swap in PP
on PAPA: l21=0l_{21} = 0, l31=2l_{31} = 2, then l32=3l_{32} = 3
same elimination as before
P=(010100001)P = \begin{pmatrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}, L=(100010231)L = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 2 & 3 & 1 \end{pmatrix}, U=(121011004)U = \begin{pmatrix} 1 & 2 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 4 \end{pmatrix}
det⁡(A)=−4\det(A) = -4: one swap flips the sign
Factor your own matrix in the matrix calculator.

See it happen

Each elimination step is a multiplication by a simple lower triangular matrix. Undoing all of them at once just puts the multipliers back in their places, which is why LL costs no extra arithmetic. Once A=LUA = LU is stored, every new right-hand side needs only two quick triangular solves instead of a full elimination. Watch LL fill in the LU decomposition visualizer.

Common mistakes

Storing the negated multipliers

✗ L=(100−210−4−31)L = \begin{pmatrix} 1 & 0 & 0 \\ -2 & 1 & 0 \\ -4 & -3 & 1 \end{pmatrix}
✓ LL holds the multipliers that were subtracted: 22, 44 and 33

Pushing on with a zero pivot

✗ dividing by a11=0a_{11} = 0 in (0111)\begin{pmatrix} 0 & 1 \\ 1 & 1 \end{pmatrix}
✓ swap the rows first and write PA=LUPA = LU

Scaling rows during elimination

✗ dividing row 1 by 22 to make the pivot 11
✓ only subtract multiples of pivot rows; the pivots stay on the diagonal of UU

Forgetting P when solving

✗ solving Ly=bL\mathbf{y} = \mathbf{b} after factoring PA=LUPA = LU
✓ solve Ly=PbL\mathbf{y} = P\mathbf{b}: permute b\mathbf{b} the same way