Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


LU Decomposition


Gaussian elimination with the multipliers kept: the working matrix becomes U, the multipliers fill L, and a forced row swap turns A = LU into PA = LU.

Preset?The LU decomposition writes a square matrix as A = LU with L unit lower triangular and U upper triangular. It is Gaussian elimination with the multipliers kept: every time a multiple of the pivot row is subtracted from a row below, that multiple goes into L and the cleared row goes into U. If a zero pivot appears, two rows are swapped and the factorization becomes PA = LU. Solving A x = b then costs two triangular solves, L y = b and U x = y.
Size (square)
A3× 3
Entries of A
A3×3
2
1
1
4
3
3
8
7
9
=
L3×3
1
0
0
?
1
0
?
?
1
·
U3×3
2
1
1
4
3
3
8
7
9
Step 1 / 7

Row operations

1LU decomposition of a 3×3 matrix
A will be written as A = LU: L unit lower triangular (ones on the diagonal, zeros above — drawn already), U upper triangular. The method is Gaussian elimination on a working copy of A, which becomes U, while every multiplier used to clear an entry is stored in the same position of L. If a pivot is zero, two rows are swapped and the result reads PA = LU.
Elimination with the multipliers kept: the working matrix becomes U, the multipliers fill L. Learn more about the opening scene · what it is








Key Terms

LU decomposition — the factorization A=LUA = LU of a square matrix into a lower triangular LL and an upper triangular UU.

Unit lower triangular — ones on the diagonal and zeros above it; the Doolittle convention used here, which makes LL unique.

Upper triangular — zeros below the diagonal; UU is the row echelon form that Gaussian elimination produces.

Multiplieri,k=ui,k/uk,k\ell_{i,k} = u_{i,k} / u_{k,k}, the multiple of the pivot row subtracted from row ii to clear its entry in column kk; it is stored at position (i,k)(i, k) of LL.

Pivot — the diagonal entry uk,ku_{k,k} used to clear column kk; it must be non-zero.

Partial pivoting — swapping rows to bring a non-zero (or the largest) entry into the pivot position; the factorization then reads PA=LUPA = LU with PP a permutation matrix.

Forward substitution — solving Ly=bL\mathbf{y} = \mathbf{b} from the top row down.

Back substitution — solving Ux=yU\mathbf{x} = \mathbf{y} from the bottom row up.

Getting Started with the Visualizer

Choose a matrix, then watch LL and UU fill in as the elimination runs.

• Use the Preset pills for six matrices chosen to show different outcomes: a classic integer case, negative pivots, a forced row swap, a 2×22 \times 2, a 4×44 \times 4 Pascal matrix, and a singular matrix
• Use the Size stepper for 2×22 \times 2 up to 4×44 \times 4; resizing keeps the existing entries and pads with the identity
• Edit any entry directly in the grid, or press Shuffle for random small integers, with a zero planted in the corner three times in ten so the swap branch turns up
• Hover the ? icon for a reminder of what the factorization is and why it is the standard way to solve linear systems
• Press play or step manually; the step log on the right lists every row operation

The layout reads A=LUA = L \cdot U throughout. LL starts with its ones and zeros already drawn, since they are known before any arithmetic, and UU starts as a copy of AA that the row operations turn triangular.

How the Elimination Runs

The visualizer processes the columns from left to right, clearing everything below each pivot.

Pivot — the diagonal entry uk,ku_{k,k} of the working matrix is marked; if it is zero and a non-zero entry sits below, a swap scene exchanges the two rows first
Eliminate — for each row ii below the pivot, the multiplier i,k=ui,k/uk,k\ell_{i,k} = u_{i,k} / u_{k,k} is written into LL and i,k\ell_{i,k} times the pivot row is subtracted from row ii, one scene per row
Done — the working matrix is UU, LL holds every multiplier, and LULU reproduces AA

A swap is applied in three places at once: the working matrix, the copy of AA on the left, which is relabelled PAPA, and the multipliers already stored in LL, which travel with their rows. When a zero pivot has nothing non-zero below it, the column is skipped, the multipliers under it are zero, and the zero stays on the diagonal of UU: the matrix is singular, but the factorization still exists.

The Opening Scene: L Half Known, U a Copy of A

The player opens with AA on the left, LL in the middle showing its ones on the diagonal and zeros above in grey, and UU on the right as an identical copy of AA.

Nothing has been eliminated yet. What the scene establishes is what is known before any arithmetic: the shape of LL is fixed by the convention, and UU is whatever the row operations leave behind.
A3×3211433879=L3×3100?10??1·U3×3211433879
Opening scene, frozen

A on the left, L with its ones and zeros already drawn in grey, and U as a copy of A. The shape of L is fixed by convention; only the entries below its diagonal are still to be found.

Drawing the known part of LL up front makes the bookkeeping visible: only the entries below the diagonal are unknown, one for each row operation that elimination will perform, and they will be filled in the order the operations happen.

The copy of AA on the left is not decorative. It stays fixed for comparison, and if a swap becomes necessary its rows are exchanged and it is relabelled PAPA, so that the identity on screen is always literally true.

Marking a Pivot

Each column begins by marking its pivot, the diagonal entry of the working matrix. Everything below it in that column is about to be cleared by subtracting multiples of the pivot row.

The frozen picture below is the first pivot of the classic preset, the 22 at (1,1)(1,1), with its row highlighted.
A3×3211433879=L3×3100?10??1·U3×3211433879
First pivot, frozen

The 2 at (1,1) marked as the pivot for column 1, its row highlighted. It is the divisor in every multiplier for this column, which is why a pivot may not be zero.

The pivot is the divisor in every multiplier for its column, which is why it cannot be zero. In exact arithmetic any non-zero pivot will do; in floating point a small pivot produces large multipliers and amplifies rounding error, so practical solvers swap in the largest available entry even when the current one is non-zero.

The pivots end up as the diagonal of UU, and their product is the determinant. Each non-zero pivot is one more independent row confirmed, exactly as in the rank computation.

Eliminating and Recording the Multiplier

For each row below the pivot, the multiplier i,k=ui,k/uk,k\ell_{i,k} = u_{i,k} / u_{k,k} is computed, written into LL at (i,k)(i, k), and used: i,k\ell_{i,k} times the pivot row is subtracted from row ii of the working matrix, clearing its entry in column kk.

The frozen picture below is the last elimination of the classic preset: 3,2=3\ell_{3,2} = 3 stored in LL, and row 33 of the working matrix cleared to make UU triangular.
A3×3211433879=L3×3100210431·U3×3211011002
Last elimination, frozen

3,2 = 3 written into L and row 3 of the working matrix cleared: U is now triangular. The multiplier is kept, not discarded - it is what lets LU rebuild A.

This is the one step that distinguishes LU from plain elimination: the multiplier is not thrown away. Row reduction as usually taught discards it once the entry is cleared; LU keeps it, because the multiplier is precisely the information needed to reverse the operation, and reversing all of them is what multiplies UU back into AA.

The sign convention is worth fixing in mind. The operation subtracts \ell times the pivot row; LL stores ++\ell. Row ii of LULU is then i,1(row 1 of U)++1(row i of U)\ell_{i,1} \cdot (\text{row } 1 \text{ of } U) + \cdots + 1 \cdot (\text{row } i \text{ of } U), which adds back everything that was subtracted.

Swapping Rows: PA = LU

When the pivot position holds a zero and a row below has a non-zero entry in that column, the two rows are exchanged. The swap is applied to the working matrix, to the copy of AA on the left, which becomes PAPA, and to any multipliers already stored in LL, which move with their rows.

The frozen picture below is the swap preset's first move: R1R2R_1 \leftrightarrow R_2 before any elimination, because the original (1,1)(1,1) entry is 00.
PA3×3123012259=L3×3100?10??1·U3×3123012259
Forced row swap, frozen

The swap preset's first move: a 0 in the (1,1) position, so R1 and R2 are exchanged in the working matrix and in the copy of A, now labelled PA. The result will read PA = LU.

A matrix with a zero in the pivot position may have no LULU factorization at all; the 2×22 \times 2 matrix with rows (0,1)(0, 1) and (1,0)(1, 0) is the standard example. Swapping rows repairs this, at the price of factoring a permuted matrix instead: PA=LUPA = LU, where PP records the exchanges.

The permutation is harmless for solving systems, since Ax=bA\mathbf{x} = \mathbf{b} is the same as PAx=PbPA\mathbf{x} = P\mathbf{b}, and it contributes only a sign to the determinant. Moving the stored multipliers along with the rows is the step most often forgotten, and it is what keeps LL consistent with the reordered matrix.

The Completed Factorization

The final scene shows UU upper triangular with its diagonal marked, LL with every multiplier in place, and the identity A=LUA = LU, or PA=LUPA = LU if a swap occurred, holding on screen.

The frozen picture below is the classic preset finished: multipliers 22, 44 and 33 in LL, diagonal 22, 11 and 22 in UU, determinant 44.
A3×3211433879=L3×3100210431·U3×3211011002
Completed factorization, frozen

Multipliers 2, 4 and 3 in L, diagonal 2, 1 and 2 in U, and A = LU holding on screen. The product of the diagonal, 4, is det A.

From here every use of the factorization is a triangular solve. To solve Ax=bA\mathbf{x} = \mathbf{b}, first solve Ly=bL\mathbf{y} = \mathbf{b} from the top down, which is trivial because LL is unit lower triangular, then Ux=yU\mathbf{x} = \mathbf{y} from the bottom up. Two passes, each about n2n^2 operations, against the n3n^3 of the factorization itself, which is done once.

That asymmetry is the whole economy of the method. A simulation that solves the same system for thousands of right-hand sides factors once and substitutes thousands of times, and the determinant and inverse, if ever needed, come from the same LL and UU.

Reading the Scene Player

Each scene shows AA (or PAPA) on the left, LL in the middle and the working matrix UU on the right, with the row operation in the caption.

• In a pivot scene, the pivot cell of UU is accent and its row is primary
• In an eliminate scene, the pivot row is primary, the row being cleared is secondary, the entry being turned into 00 is accent, and the multiplier that appears in LL is accent too, with an arrow from the cleared entry to its new home in LL
• In a swap scene, the two rows exchanging places are primary and secondary in all three matrices
• In the done scene, every multiplier in LL is secondary and the diagonal of UU is accent, or muted where a zero sits on it
• The known entries of LL, the ones on the diagonal and the zeros above, are drawn in grey from the first scene; fractions are shown as a/ba/b in a smaller font

Choosing a Matrix

The six presets each make a different point.

Classic 3×33 \times 3 — integer multipliers 22, 44 and 33, no swaps, and UU with a clean diagonal; the textbook example
Negative pivots — a 1-1 pivot and negative multipliers, to show that signs pass through the arithmetic unchanged
Needs a swap — a zero in the (1,1)(1,1) position; the first thing the run does is exchange two rows, and the result is PA=LUPA = LU
2×22 \times 2 — a single multiplier, and a fraction, in the smallest case
Pascal 4×44 \times 4 — the matrix of binomial coefficients factors into two Pascal triangles, LL lower and UU upper, a classic identity made visible
Singular — elimination produces a zero on the diagonal of UU that no swap can remove; the factorization exists, the inverse does not

Editing entries by hand is the quickest way to see how the multipliers respond: change one entry of the classic preset and watch which entries of LL and UU move.

What the LU Decomposition Is

Gaussian elimination turns a square matrix AA into an upper triangular UU by subtracting multiples of rows from the rows below them. Each such operation is itself a matrix: subtracting \ell times row kk from row ii is left-multiplication by an elementary matrix EE with -\ell at position (i,k)(i, k). Collecting them, EmE1A=UE_m \cdots E_1 A = U, so

A=(EmE1)1U=LUA = (E_m \cdots E_1)^{-1} U = LU


The inverse of that product of elementary matrices turns out to be very simple: it is unit lower triangular and its entry at (i,k)(i, k) is exactly the multiplier i,k\ell_{i,k} that was used. That is why the tool can fill LL directly, one multiplier at a time, without ever computing an inverse.

L=(1002,1103,13,21),U=the echelon formL = \begin{pmatrix} 1 & 0 & 0 \\ \ell_{2,1} & 1 & 0 \\ \ell_{3,1} & \ell_{3,2} & 1 \end{pmatrix}, \qquad U = \text{the echelon form}


The factorization fails only when a pivot is zero. If some row below has a non-zero entry in that column, swapping the rows fixes it, and the swaps together form a permutation matrix PP with PA=LUPA = LU. In floating point, rows are swapped even when the pivot is merely small, choosing the largest available entry; that is partial pivoting, and every serious solver does it. This tool swaps only when forced, so that the connection to plain elimination stays visible.

For the full treatment, including the elementary-matrix derivation and the Crout and Cholesky variants, see the LU decomposition theory page.

Key Properties

The factorization inherits the properties of its triangular factors.

Existence: A=LUA = LU without swaps exists exactly when every leading principal submatrix of AA is non-singular; with swaps, PA=LUPA = LU exists for every square AA
Uniqueness: with LL unit lower triangular, the factorization is unique when it exists
Determinant: detA=detLdetU=u1,1u2,2un,n\det A = \det L \cdot \det U = u_{1,1} u_{2,2} \cdots u_{n,n}, times ±1\pm 1 for the permutation
Singularity: AA is singular exactly when a zero appears on the diagonal of UU
Solving systems: Ax=bA\mathbf{x} = \mathbf{b} becomes Ly=bL\mathbf{y} = \mathbf{b} then Ux=yU\mathbf{x} = \mathbf{y}, two triangular solves
Reuse: the factorization is computed once and reused for every right-hand side b\mathbf{b}
Cost: about 23n3\tfrac{2}{3}n^3 operations to factor, 2n22n^2 per solve
Symmetric positive definite: U=DLTU = DL^T, giving the Cholesky form A=LDLTA = LDL^T or A=RTRA = R^TR

Why It Matters

LU is how linear systems are actually solved.

Solving Ax=bA\mathbf{x} = \mathbf{b}: computing A1A^{-1} is never the method; factoring AA once and doing two triangular solves is cheaper and more accurate
Many right-hand sides: the same LL and UU serve every b\mathbf{b}, which is the situation in simulations and iterative methods
Determinants: the product of the diagonal of UU is the practical way to compute detA\det A for anything larger than 3×33 \times 3
Inverses: when an inverse is genuinely needed, it is found by solving Ax=ejA\mathbf{x} = \mathbf{e}_j for each column, from the same factorization
Banded and sparse systems: LL and UU inherit the band structure of AA, so tridiagonal and finite-difference systems factor in linear time
The bridge to theory: LL is the record of Gaussian elimination as a matrix, which is what turns row reduction from a procedure into algebra

Worked Example

Take the classic preset,

A=(211433879)A = \begin{pmatrix} 2 & 1 & 1 \\ 4 & 3 & 3 \\ 8 & 7 & 9 \end{pmatrix}


Column 1, pivot 22. Multipliers 2,1=4/2=2\ell_{2,1} = 4/2 = 2 and 3,1=8/2=4\ell_{3,1} = 8/2 = 4. Subtract 2R12R_1 from R2R_2 and 4R14R_1 from R3R_3:

(211011035)\begin{pmatrix} 2 & 1 & 1 \\ 0 & 1 & 1 \\ 0 & 3 & 5 \end{pmatrix}


Column 2, pivot 11. Multiplier 3,2=3/1=3\ell_{3,2} = 3/1 = 3. Subtract 3R23R_2 from R3R_3:

U=(211011002),L=(100210431)U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{pmatrix}, \qquad L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ 4 & 3 & 1 \end{pmatrix}


Check row 33 of LULU: 4(2,1,1)+3(0,1,1)+1(0,0,2)=(8,7,9)4 \cdot (2, 1, 1) + 3 \cdot (0, 1, 1) + 1 \cdot (0, 0, 2) = (8, 7, 9). The determinant is 212=42 \cdot 1 \cdot 2 = 4, and expanding detA\det A directly gives 2(2721)1(3624)+1(2824)=42(27 - 21) - 1(36 - 24) + 1(28 - 24) = 4 as well.

For the swap preset, the (1,1)(1,1) entry is 00, so R1R2R_1 \leftrightarrow R_2 comes first and the factorization is of the permuted matrix. Its UU has diagonal 1,1,11, 1, 1, so detA=1|\det A| = 1; the swap contributes a sign, and detA=1\det A = -1. Set the visualizer to either preset and step through to see the same operations performed.

Common Mistakes

A few mistakes recur.

Storing the negative of the multiplierLL holds i,k\ell_{i,k} itself, the multiple that was subtracted, not i,k-\ell_{i,k}; the minus sign lives in the elimination step, and LULU puts it back
Dividing by the wrong pivot — the multiplier for clearing column kk uses the current pivot uk,ku_{k,k} of the working matrix, not the original entry of AA
Forgetting to swap the stored multipliers — when rows are exchanged after some columns are done, the entries of LL already computed in those rows must be exchanged too
Dividing by a zero pivot — a zero pivot means swap, not proceed; if nothing below is non-zero, the matrix is singular
Expecting A=LUA = LU after a swap — with row exchanges the identity is PA=LUPA = LU, and forward substitution must use PbP\mathbf{b}
Trusting tiny pivots — in floating point, a small pivot produces huge multipliers and loses precision; that is why software pivots on the largest entry, not merely a non-zero one