Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Lower-Upper Decomposition






Gaussian Elimination as a Matrix Factorization

The LU decomposition factors a square matrix into a lower triangular factor L and an upper triangular factor U. The upper factor is the row echelon form; the lower factor stores the multipliers used to get there. Once computed, the factorization converts every subsequent system solve into two cheap triangular substitutions — making LU the workhorse of direct linear system solvers.



What LU Decomposition Is

The LU decomposition writes an n×nn \times n matrix AA as

LU Decomposition
A=LUA = LU

where LL is lower triangular with ones on the diagonal (unit lower triangular) and UU is upper triangular. The matrix UU is the row echelon form of AA, and LL stores the multipliers that Gaussian elimination used to produce it.

The factorization captures the entire elimination process in a reusable form. Instead of performing elimination from scratch for every new right-hand side b\mathbf{b}, the work is done once (producing LL and UU) and reused cheaply for each solve.

LU Notation

Notation

LU Notation

Two letters chosen for what they look like, a diagonal of ones nobody writes down as a choice, and a permutation whose meaning depends entirely on which side of AA it stands.
The echelon form that UU turns out to be, and the pivot vocabulary that comes with it, are set out at row echelon form. The row operations themselves, their arrow convention and the augmented bar belong to Gaussian elimination, and the general habit of naming a factorisation by its factors is described at the singular value decomposition.
A = LU
A equals L U — A written as a lower triangular matrix times an upper triangular one
The letters are mnemonic rather than arbitrary: LL is lower, UU is upper. That is unusual. Most factorisations pick letters for the role a factor plays, and here they name the shape instead, which is why the equation can be read off without a legend.
CasesThe two factors are not interchangeable. ULUL is a different product describing a different matrix, and the order in A=LUA = LU is fixed by the elimination that produced it — the lower factor records what was done, the upper factor records what was left.
Also writtenGerman-language texts write A=LRA = LR, keeping LL and taking RR from the word for the right-hand, upper triangle. The three-factor spelling A=LDUA = LDU pulls the pivots out into a diagonal DD so that both triangular factors carry ones.
Do not confuseTreating LULU as an expression waiting to be multiplied out. The point of the factorisation is that the pair is kept and reused; multiplying it back to AA is only ever a check.
Same glyph elsewhereThe letter UU names the orthogonal left factor at the singular value decomposition, where the clash with upper triangular is set out.
L = \begin{pmatrix} 1 & 0 & 0 \\ l_{21} & 1 & 0 \\ l_{31} & l_{32} & 1 \end{pmatrix}
L is unit lower triangular — ones along the diagonal, multipliers below it
Unit here refers to the diagonal entries being 11 and to nothing else. The ones are a normalisation that has to be supplied from outside, because A=LUA = LU on its own does not determine the factors: for any invertible diagonal DD, the pair LDLD and D1UD^{-1}U multiplies to the same AA. Fixing LL to carry ones removes the freedom and makes the factorisation unique.
CasesThe three-factor form A=LDUA = LDU makes the choice visible instead of silent, putting the pivots in DD and leaving both triangular factors with unit diagonals.
Also writtenSome treatments normalise UU instead, giving UU the ones and leaving the pivots in LL. Both conventions produce a correct A=LUA = LU, and they produce different LL and UU.
Do not confuseReading unit as unit length or orthonormal columns, neither of which is claimed. The second misreading is expecting UU to have ones as well: the diagonal of UU holds the pivots, and it is their product that gives the determinant.
PA = LU
P A equals L U — permute the rows of A, then factor the result
Which side PP stands on is the whole content of the line. On the left it multiplies the rows of AA, and the equation asserts an order of events: the swaps are decided first, and elimination runs on the reordered matrix. The factorisation belongs to PAPA, not to AA.
CasesRearranged forms say the same thing: since PP is a permutation, P1=PTP^{-1} = P^{T}, so A=PTLUA = P^{T}LU. Numerical libraries commonly return the transposed permutation and report A=PLUA = PLU — the same letter naming the inverse matrix, which is worth checking before mixing output from two sources.
Also writtenThe row swaps are sometimes reported as a list of indices rather than a matrix, which stores the same information without committing to a side.
Do not confuseDropping PP once the factors are in hand. Solving Ax=bA\mathbf{x} = \mathbf{b} requires the right-hand side to be permuted too, so forward substitution runs on PbP\mathbf{b}; using b\mathbf{b} untouched silently solves a system with its rows in the wrong order.
Same glyph elsewherePP carries the eigenvectors at diagonalization, where it is an arbitrary invertible matrix rather than a rearrangement of rows.
l_{ij}, \quad i > j
the entry of L in row i, column j, below the diagonal
These entries are a transcript, not a computation on AA. Each one is the multiplier that cleared position (i,j)(i, j) during forward elimination, so LL is a record of the procedure and UU is its result.
CasesThe sign follows subtraction. Subtracting 22 times row 11 from row 22 stores +2+2; adding row 11 to row 33 stores 1-1. The number in LL therefore reads with the opposite sign to the operation as it is usually spoken.
Also writtenThe multipliers are written mijm_{ij} while elimination is being described and lijl_{ij} once they have been placed in the matrix — two names for one number at two moments.
Do not confuseReading the packed storage as a matrix. Since the ones in LL and the zeros in UU carry no information, software keeps both factors in one n×nn \times n array with the multipliers in the lower triangle and UU in the upper. Printed, it looks like a single matrix and is neither factor.

Construction from Gaussian Elimination

Forward elimination on AA applies a sequence of row-addition operations, each represented by an elementary matrix EiE_i. The product EkE2E1A=UE_k \cdots E_2 E_1 A = U reduces AA to upper triangular form.

Rearranging: A=E11E21Ek1UA = E_1^{-1} E_2^{-1} \cdots E_k^{-1} U. Each EiE_i is a lower triangular matrix that adds a multiple of one row to a row below. Its inverse simply negates the multiplier. The product L=E11E21Ek1L = E_1^{-1} E_2^{-1} \cdots E_k^{-1} is lower triangular, with the multipliers sitting in the sub-diagonal positions.

Worked Example


A=(211402253)A = \begin{pmatrix} 2 & 1 & -1 \\ 4 & 0 & 2 \\ -2 & 5 & 3 \end{pmatrix}


Subtract 22 times row 11 from row 22 (multiplier m21=2m_{21} = 2) and add row 11 to row 33 (multiplier m31=1m_{31} = -1):

(211024062)\begin{pmatrix} 2 & 1 & -1 \\ 0 & -2 & 4 \\ 0 & 6 & 2 \end{pmatrix}


Add 33 times row 22 to row 33 (multiplier m32=3m_{32} = -3):

U=(2110240014)U = \begin{pmatrix} 2 & 1 & -1 \\ 0 & -2 & 4 \\ 0 & 0 & 14 \end{pmatrix}


The multipliers fill LL: L=(100210131)L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ -1 & -3 & 1 \end{pmatrix}.

Verification: LU=(211402253)=ALU = \begin{pmatrix} 2 & 1 & -1 \\ 4 & 0 & 2 \\ -2 & 5 & 3 \end{pmatrix} = A.
A3×3211433879=L3×3100210431·U3×3211011002
The multiplier stored, not discarded

Ordinary elimination throws away the multiplier once the zero is in place. Here it is kept and written into the lower factor, so L records the elimination and U records the result of it. Nothing extra is computed; the same arithmetic is simply being saved. Follow both factors filling in on the LU decomposition visualizer.

The factorisation is therefore a by-product of elimination rather than a separate algorithm with its own cost.

The Structure of L and U

The lower factor LL is unit lower triangular: ones on the diagonal and multipliers below. Entry lijl_{ij} (with i>ji > j) is the multiplier used to eliminate position (i,j)(i, j) during forward elimination. The diagonal is always ones because no row scaling is performed — only row additions.

The upper factor UU is the echelon form: pivots on the diagonal, zeros below, and the result of all elimination steps. The diagonal entries of UU are the pivots, and their product gives the determinant: det(A)=det(L)det(U)=1u11u22unn\det(A) = \det(L)\det(U) = 1 \cdot u_{11}u_{22}\cdots u_{nn}.

The factorization stores LL and UU compactly. Since LL has ones on the diagonal (which need not be stored) and UU has zeros below the diagonal (which need not be stored), both factors fit in a single n×nn \times n array: the lower triangle holds the multipliers and the upper triangle holds UU.

The two factors compare cleanly on the same set of attributes — diagonal, below diagonal, above diagonal, role — as the table below shows.
Decompositions · LU

What each factor holds

Between them LL and UU store the whole elimination — UU is what was left, LL is what was done. Read region by region, neither factor wastes a position.

3factors
TypeConditionon the diagonalbelow itabove it
What the elimination produced
U — upper triangular§ 3the echelon form of AAthe pivots — uii=±detA\prod u_{ii} = \pm\det Azeros — what elimination removedthe surviving entries
What the elimination did
L — unit lower triangular§ 3the multipliers, in positionall ones — not storedthe multiplier ij=mij\ell_{ij} = m_{ij}zeros
What the pivoting recorded
P — permutation§ 5the row swaps, if anyones where no swap occurreda single one per rowa single one per row
The two triangles are complementary, so both fit in one n×nn \times n array with nothing overlapping: UU on and above the diagonal, LL strictly below, and the unit diagonal of LL left implicit because it is known. Storing a factorization therefore costs no more memory than storing AA did.
What each factor holds·/linear-algebra/decompositions/lower-upperLearn Math Class
The two triangles occupy complementary regions, which is not a coincidence but the reason the factorization is cheap to store. UU owns the diagonal and everything above it; LL owns everything strictly below; and the unit diagonal of LL need not be written down because it is known in advance. Both factors therefore fit into the same n×nn \times n array the original matrix occupied, with no position used twice and none left empty.

When LU Exists Without Pivoting

The factorization A=LUA = LU without row swaps exists if and only if every leading principal submatrix of AA is nonsingular. The kk-th leading principal submatrix is the upper-left k×kk \times k block of AA, and its determinant must be nonzero for k=1,2,,nk = 1, 2, \dots, n.

When a zero appears in a pivot position during elimination, no row-addition operation can produce a nonzero pivot — a row swap is required. The simple A=LUA = LU factorization breaks down, and the pivoted version PA=LUPA = LU is needed.

For example, A=(0110)A = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} has no LULU factorization without pivoting: the (1,1)(1,1) entry is zero, and no multiple of row 11 can create a nonzero pivot. But after swapping the two rows, elimination proceeds immediately.

Partial Pivoting: PA = LU

Partial pivoting modifies the elimination process: at each step, the row with the largest absolute value in the current pivot column (among rows at or below the pivot position) is swapped into the pivot position. All row swaps are recorded in a permutation matrix PP.

The factorization becomes:

PA LU Partial Pivoting
PA=LUPA = LU

where PP is the product of all row-swap permutation matrices. This factorization exists for every invertible matrix — partial pivoting eliminates the restriction on leading principal submatrices.

Partial pivoting also improves numerical stability. Small pivots amplify rounding errors (dividing by a number near zero magnifies imprecision), and selecting the largest available pivot keeps the multipliers in LL bounded by 11 in absolute value, limiting error accumulation.

In numerical software, LU with partial pivoting is the default — the unpivoted version A=LUA = LU is a theoretical simplification that is rarely used in practice.
PA3×3123012259=L3×3100?10??1·U3×3123012259
A row swap recorded in the permutation

A zero, or an uncomfortably small number, has appeared where a pivot was needed, so rows have been exchanged and the exchange logged in P. This is why the honest statement of the factorisation is PA = LU: without the permutation there are perfectly ordinary matrices that have no LU at all. Trigger a swap on the LU decomposition visualizer.

In practice pivoting is used even when it is not strictly required, because small pivots damage accuracy long before they reach zero.

Solving Systems with LU

Given PA=LUPA = LU, the system Ax=bA\mathbf{x} = \mathbf{b} is solved in two steps:

LU Solve Steps
Ax=b    {Ly=Pb(forward sub)Ux=y(back sub)A\mathbf{x} = \mathbf{b} \;\Longleftrightarrow\; \begin{cases} L\mathbf{y} = P\mathbf{b} & (\text{forward sub}) \\ U\mathbf{x} = \mathbf{y} & (\text{back sub}) \end{cases}

Forward substitution: solve Ly=PbL\mathbf{y} = P\mathbf{b} for y\mathbf{y}. Since LL is lower triangular, this starts at the top and works downward — each equation involves one new unknown plus previously solved values. Cost: O(n2)O(n^2).

Back substitution: solve Ux=yU\mathbf{x} = \mathbf{y} for x\mathbf{x}. Since UU is upper triangular, this starts at the bottom and works upward. Cost: O(n2)O(n^2).

The factorization itself costs 23n3\frac{2}{3}n^3 operations. Each subsequent solve costs O(n2)O(n^2). For kk systems with the same coefficient matrix but different right-hand sides b1,,bk\mathbf{b}_1, \dots, \mathbf{b}_k: factor once at cost 23n3\frac{2}{3}n^3, then solve kk times at cost kn2kn^2. When kk is large, the per-system cost drops to essentially O(n2)O(n^2) — far cheaper than kk independent eliminations at 23n3\frac{2}{3}n^3 each.

LU and the Determinant

The determinant of AA is a free byproduct of the LU factorization. Since det(L)=1\det(L) = 1 (the diagonal is all ones) and det(U)=u11u22unn\det(U) = u_{11}u_{22}\cdots u_{nn} (the product of the diagonal for a triangular matrix), with pivoting each row swap flips the sign:

Determinant via LU
det(A)=(1)si=1nuii\det(A) = (-1)^s \prod_{i=1}^{n} u_{ii}

where ss is the number of row swaps recorded in PP. Without pivoting (s=0s = 0), the sign factor drops and det(A)=u11u22unn\det(A) = u_{11}u_{22}\cdots u_{nn}.

This makes determinant computation essentially free once LU is available — just multiply the diagonal of UU and account for the sign. It is far more efficient than cofactor expansion, and it is the method every numerical library uses.

LU and the Inverse

To compute A1A^{-1}, solve Axj=ejA\mathbf{x}_j = \mathbf{e}_j for each standard basis vector ej\mathbf{e}_j, j=1,,nj = 1, \dots, n. The solutions x1,,xn\mathbf{x}_1, \dots, \mathbf{x}_n are the columns of A1A^{-1}.

With LU: factor AA once (23n3\frac{2}{3}n^3), then solve nn systems (n×O(n2)=O(n3)n \times O(n^2) = O(n^3)). Total cost: roughly 83n3\frac{8}{3}n^3 — cheaper than nn independent eliminations.

In practice, computing A1A^{-1} explicitly is rarely the right approach. Solving Ax=bA\mathbf{x} = \mathbf{b} via LU is faster than multiplying A1bA^{-1}\mathbf{b}, and more numerically stable. The inverse formula is primarily a theoretical tool; for computation, LU solves are preferred.

Worked Example: 4×4 with Pivoting

A=(0213103131022310)A = \begin{pmatrix} 0 & 2 & 1 & 3 \\ 1 & 0 & 3 & -1 \\ 3 & 1 & 0 & 2 \\ 2 & 3 & 1 & 0 \end{pmatrix}


The (1,1)(1,1) entry is zero — a row swap is needed. The largest entry in column 11 is 33 in row 33. Swap rows 11 and 33:

(3102103102132310)\begin{pmatrix} 3 & 1 & 0 & 2 \\ 1 & 0 & 3 & -1 \\ 0 & 2 & 1 & 3 \\ 2 & 3 & 1 & 0 \end{pmatrix}


Eliminate below the (1,1)(1,1) pivot. Multipliers: m21=1/3m_{21} = 1/3, m31=0m_{31} = 0, m41=2/3m_{41} = 2/3:

(310201/335/3021307/314/3)\begin{pmatrix} 3 & 1 & 0 & 2 \\ 0 & -1/3 & 3 & -5/3 \\ 0 & 2 & 1 & 3 \\ 0 & 7/3 & 1 & -4/3 \end{pmatrix}


The largest entry in column 22 below position (2,2)(2,2) is 7/37/3 in row 44. Swap rows 22 and 44. Continue elimination on columns 22 and 33 with the appropriate multipliers.

After completing all steps, the factorization PA=LUPA = LU is assembled with PP recording both row swaps, LL storing all multipliers, and UU storing the final upper triangular result. Verification: LU=PALU = PA.

Computational Cost

The LU factorization of an n×nn \times n matrix requires roughly 23n3\frac{2}{3}n^3 arithmetic operations (multiplications and additions). Each triangular solve (forward or back substitution) requires roughly n2n^2 operations.

For a single system Ax=bA\mathbf{x} = \mathbf{b}, LU costs about the same as Gaussian elimination applied directly. The advantage appears with multiple right-hand sides: kk systems sharing the same AA cost 23n3+2kn2\frac{2}{3}n^3 + 2kn^2, versus 23kn3\frac{2}{3}kn^3 for kk independent eliminations.

Compared to alternatives: Cramer's rule costs O(nn!)O(n \cdot n!) — absurdly expensive. Explicit inverse computation costs roughly 2n32n^3. The Cholesky factorization costs 13n3\frac{1}{3}n^3 but requires symmetry and positive definiteness. LU is the general-purpose baseline — the standard direct solver for dense linear systems in scientific computing.

These options can be set side by side on cost per system, cost amortized over many systems, and the matrix conditions each requires.
Method Cost for one system Cost for k systems (same A) Restrictions
LU with partial pivoting ≈ 2n3/3 + O(n2) 2n3/3 + 2kn2 A square and invertible
Cholesky ≈ n3/3 + O(n2) n3/3 + 2kn2 A symmetric positive definite
Explicit inverse A−1b ≈ 8n3/3 to form A−1, then 2n2 per multiply 8n3/3 + 2kn2 numerically less stable; rarely the right choice
Cramer's rule O(n · n!) — impractical beyond n ≈ 4 k × O(n · n!) theoretical only; not used in computation

Summary: What LU Computes

Once PA=LUPA = LU is in hand, three of the most common matrix-level computations — solving a system, taking the determinant, and forming the inverse — collapse to cheap operations on the factors. The table below collects each task with the procedure it reduces to, the cost given the factorization, and the cost of doing the same task from scratch for comparison.
The split below is between paying once and paying per use. The factorization is the expensive step and happens a single time; everything after it is a triangular solve or a product along a diagonal. Reading the cost column downward shows why the decomposition is stored rather than recomputed — the first row is cubic, the rest are quadratic or less.
Decompositions · LU

What LU computes, and at what cost

The factorization costs 23n3\tfrac{2}{3}n^3 once. Everything below reuses it, and the cost column is the reason the decomposition exists at all — each task afterwards is cheaper than redoing the elimination.

4tasks
The factorization itself1
1
once per matrix
23n3\tfrac{2}{3}n^3 flops
Gaussian elimination with the multipliers kept rather than discarded — LL holds what was subtracted, UU holds what remained, PP records the row swaps. The elimination was being done anyway; LU is the observation that its byproducts are worth storing.
Reusing it — cost per use3
2
forward solve Ly=PbL\mathbf{y} = P\mathbf{b}, then back solve Ux=yU\mathbf{x} = \mathbf{y}
2n22n^2 per right-hand side
Two triangular solves, each n2n^2. The saving arrives on the second right-hand side: a fresh elimination would cost 23n3\tfrac{2}{3}n^3 again, while reusing the factors costs n2n^2 — which is why LU is what a solver stores when the matrix is fixed and b\mathbf{b} varies.
3
ss = number of row swaps in PP
detA=(1)suii\det A = (-1)^{s} \prod u_{ii}
Multiply the diagonal of UU and correct the sign for the swaps — O(n)O(n) once the factorization exists. Cofactor expansion is O(n!)O(n!) for the same number, which is the gap between a definition and a method.
4
solve Axi=eiA\mathbf{x}_i = \mathbf{e}_i for each ii
2n32n^3 total
nn solves at 2n22n^2 each. Worth doing only when the inverse is genuinely wanted as an object — if the goal is solving systems, the triangular solves above are three times cheaper and numerically better behaved.
The economics are the whole argument. One elimination at 23n3\tfrac{2}{3}n^3, then n2n^2 per right-hand side — so ten systems sharing a matrix cost barely more than one. Compare recomputing from scratch each time, and the saving is a factor of nn; compare inverting, and LU is three times cheaper and more accurate besides.
What LU computes, and at what cost·/linear-algebra/decompositions/lower-upperLearn Math Class
The break-even point arrives immediately. Solving one system by elimination costs 23n3\tfrac{2}{3}n^3 whether or not the factors are kept, so keeping them is free; the second right-hand side then costs 2n22n^2 instead of another 23n3\tfrac{2}{3}n^3. For a 1000×10001000 \times 1000 matrix that is two million operations against roughly seven hundred million — a factor of several hundred, on the same matrix, for a different b\mathbf{b}.
The last row is the one to read as a warning. Computing A1A^{-1} through LU is perfectly possible and rarely the right thing to do: it costs three times a single solve, and using the inverse afterwards is both slower and less accurate than the two triangular solves it replaced. The inverse is worth forming when it is the answer, not when it is a step toward one.

LU Decomposition FAQ

Do both LL and UU have ones on the diagonal?

+
Only LL does. The unit diagonal is a normalisation chosen to make the factorisation unique, and UU instead carries the pivots along its diagonal, whose product gives the determinant. Note that unit here means the entries equal one, with no claim about unit length or orthonormal columns.Read more →

Can you drop the permutation PP once you have LL and UU?

+
No, because PP recorded the row swaps and those swaps must reach the right-hand side too. Solving Ax=bA\mathbf{x} = \mathbf{b} from PA=LUPA = LU means running forward substitution on PbP\mathbf{b}, not on b\mathbf{b}. Using the untouched vector silently solves a system whose rows are in the wrong order.Read more →

Is ULUL the same as LULU?

+
No, they are different products describing different matrices, and the order in A=LUA = LU is fixed by the elimination that produced it: the lower factor records what was done, the upper factor what was left. The pair is also meant to be kept and reused, so multiplying back to AA is only ever a check.Read more →