Skip to main content
© 2026 ePowerAI. All rights reserved.
CoursesContact
eAI
CoursesContact
Week 3: Elimination and LU Factorization
Linear Algebra
01Week 1: Vectors and Linear Combinations
02Week 2: Linear Transformations and Matrices
03Week 3: Elimination and LU Factorization
04Week 4: Determinants
05Week 5: Vector Spaces, Independence, and Basis
06Week 6: The Four Fundamental Subspaces
07Week 7: Orthogonality and Projections
08Week 8: Least Squares and QR
09Week 9: Eigenvalues and Eigenvectors
10Week 10: Diagonalization and Markov Matrices
11Week 11: Differential Equations
12Week 12: Symmetric and Positive Definite Matrices
13Week 13: The SVD and Complex Matrices
14Week 14: The Fourier Matrix, FFT, and PCA
Week 03· Linear Algebra20 min read

Week 3: Elimination and LU Factorization

✦Learning Outcomes
  • Solve Ax=bAx=bAx=b using Gaussian elimination
  • Express elimination steps as multiplication by elementary matrices
  • Factor a matrix as A=LUA = LUA=LU (and PA=LUPA=LUPA=LU with row exchanges)
  • Recognize when elimination fails and needs a row exchange
◆Prerequisites

Background knowledge assumed:

  • Matrix multiplication as composition of linear transformations

Recommended: Review Week 2: Linear Transformations and Matrices before starting.

Solving Systems by Elimination#

A linear system Ax=bAx = bAx=b asks for a vector xxx whose linear combination of the columns of AAA equals the right-hand side bbb. Gaussian elimination is the algorithm that turns this into an equivalent triangular system you can solve by back-substitution. The idea is simple: use each pivot to clear every entry below it, one column at a time, until only an upper triangular matrix UUU remains.

Worked 3×33 \times 33×3 example. Solve Ax=bAx = bAx=b with

A=(211433879),b=(111).A = \begin{pmatrix} 2 & 1 & 1 \\ 4 & 3 & 3 \\ 8 & 7 & 9 \end{pmatrix}, \quad b = \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix}.A=​248​137​139​​,b=​111​​.

Write the augmented matrix [A∣b][A \mid b][A∣b]:

[211143318791].\left[\begin{array}{ccc|c} 2 & 1 & 1 & 1 \\ 4 & 3 & 3 & 1 \\ 8 & 7 & 9 & 1 \end{array}\right].​248​137​139​111​​.

Column 1. The first pivot is a11=2a_{11} = 2a11​=2. Multipliers for the rows below are

ℓ21=42=2,ℓ31=82=4.\ell_{21} = \frac{4}{2} = 2, \qquad \ell_{31} = \frac{8}{2} = 4.ℓ21​=24​=2,ℓ31​=28​=4.

Replace row 2 by row2−2⋅row1\text{row}_2 - 2 \cdot \text{row}_1row2​−2⋅row1​ and row 3 by row3−4⋅row1\text{row}_3 - 4 \cdot \text{row}_1row3​−4⋅row1​:

[2111011−1035−3].\left[\begin{array}{ccc|c} 2 & 1 & 1 & 1 \\ 0 & 1 & 1 & -1 \\ 0 & 3 & 5 & -3 \end{array}\right].​200​113​115​1−1−3​​.

Column 2. The second pivot is now 111. The multiplier for row 3 is ℓ32=3/1=3\ell_{32} = 3/1 = 3ℓ32​=3/1=3. Replace row 3 by row3−3⋅row2\text{row}_3 - 3 \cdot \text{row}_2row3​−3⋅row2​:

[2111011−10020].\left[\begin{array}{ccc|c} 2 & 1 & 1 & 1 \\ 0 & 1 & 1 & -1 \\ 0 & 0 & 2 & 0 \end{array}\right].​200​110​112​1−10​​.

The coefficient matrix is now upper triangular:

U=(211011002),with right-hand side c=(1−10).U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{pmatrix}, \quad \text{with right-hand side } c = \begin{pmatrix} 1 \\ -1 \\ 0 \end{pmatrix}.U=​200​110​112​​,with right-hand side c=​1−10​​.

Back-substitution. Solve Ux=cUx = cUx=c from the bottom up:

2x3=0  ⟹  x3=0,2x_3 = 0 \implies x_3 = 0,2x3​=0⟹x3​=0, x2+x3=−1  ⟹  x2=−1,x_2 + x_3 = -1 \implies x_2 = -1,x2​+x3​=−1⟹x2​=−1, 2x1+x2+x3=1  ⟹  2x1−1=1  ⟹  x1=1.2x_1 + x_2 + x_3 = 1 \implies 2x_1 - 1 = 1 \implies x_1 = 1.2x1​+x2​+x3​=1⟹2x1​−1=1⟹x1​=1.

So

x=(1−10).x = \begin{pmatrix} 1 \\ -1 \\ 0 \end{pmatrix}.x=​1−10​​.

Check: Ax=(2−14−38−7)=(111)=bA x = \begin{pmatrix} 2-1 \\ 4-3 \\ 8-7 \end{pmatrix} = \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} = bAx=​2−14−38−7​​=​111​​=b. The pivots of UUU are 222, 111, and 222 — the successive diagonal entries used to divide when eliminating below. If any pivot is zero, this process stalls; we return to that case in the last section.

Elimination did not change the solution set: each row operation is reversible (add back the multiple you subtracted), so Ax=bAx = bAx=b and Ux=cUx = cUx=c have exactly the same xxx.


Elimination as Matrix Multiplication#

Every elimination step is left-multiplication by an elementary matrix. Week 2 treated matrix multiplication as composition of linear maps; here each elementary matrix encodes one row operation, and the product of those matrices encodes the whole elimination.

To subtract ℓ\ellℓ times row jjj from row iii, multiply on the left by the matrix EijE_{ij}Eij​ that looks like the identity except for a single nonzero off-diagonal entry −ℓ-\ell−ℓ in position (i,j)(i,j)(i,j). For our 3×33 \times 33×3 example:

E21=(100−210001)(subtract 2 times row 1 from row 2),E_{21} = \begin{pmatrix} 1 & 0 & 0 \\ -2 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} \quad\text{(subtract $2$ times row 1 from row 2)},E21​=​1−20​010​001​​(subtract 2 times row 1 from row 2), E31=(100010−401)(subtract 4 times row 1 from row 3),E_{31} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ -4 & 0 & 1 \end{pmatrix} \quad\text{(subtract $4$ times row 1 from row 3)},E31​=​10−4​010​001​​(subtract 4 times row 1 from row 3), E32=(1000100−31)(subtract 3 times row 2 from row 3).E_{32} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -3 & 1 \end{pmatrix} \quad\text{(subtract $3$ times row 2 from row 3)}.E32​=​100​01−3​001​​(subtract 3 times row 2 from row 3).

In general, when the current pivot is ajja_{jj}ajj​ (after previous steps) and the entry below it is aija_{ij}aij​, the multiplier is

ℓ=aijajj,\ell = \frac{a_{ij}}{a_{jj}},ℓ=ajj​aij​​,

and EijE_{ij}Eij​ has −ℓ-\ell−ℓ in position (i,j)(i,j)(i,j). Applying all three steps to AAA yields

E32 E31 E21 A=U.E_{32}\, E_{31}\, E_{21}\, A = U.E32​E31​E21​A=U.

Write E=E32E31E21E = E_{32} E_{31} E_{21}E=E32​E31​E21​ for the product of all elementary matrices. Then the full elimination is the single matrix equation

E⋅A=U.E \cdot A = U.E⋅A=U.

The same EEE acts on bbb: Eb=cE b = cEb=c, so Ux=cUx = cUx=c is equivalent to Ax=bAx = bAx=b. Because each EijE_{ij}Eij​ is lower triangular with 111's on the diagonal, so is EEE; each is invertible (put +ℓ+\ell+ℓ where −ℓ-\ell−ℓ was), so EEE is invertible.

Small 2×22 \times 22×2 check. For A=(2143)A = \begin{pmatrix} 2 & 1 \\ 4 & 3 \end{pmatrix}A=(24​13​), the only multiplier is ℓ=a21/a11=4/2=2\ell = a_{21}/a_{11} = 4/2 = 2ℓ=a21​/a11​=4/2=2. Then

E21=(10−21),E21A=(2101)=U.E_{21} = \begin{pmatrix} 1 & 0 \\ -2 & 1 \end{pmatrix}, \quad E_{21} A = \begin{pmatrix} 2 & 1 \\ 0 & 1 \end{pmatrix} = U.E21​=(1−2​01​),E21​A=(20​11​)=U.

That multiplier is the quantity the exercise below asks for.

Exercise · Fill in the blank

Elimination on A = [[2,1],[4,3]] uses the multiplier ℓ = a21/a11 to clear the entry below the first pivot. What is ℓ?


The LU Factorization#

From EA=UEA = UEA=U we can recover AAA by inverting EEE:

A=E−1U.A = E^{-1} U.A=E−1U.

Define L=E−1L = E^{-1}L=E−1. Then

A=LU.A = LU.A=LU.

This is the LULower-Upper (matrix factorization) factorization of AAA (when no row exchanges are needed). Because EEE is unit lower triangular, so is L=E−1L = E^{-1}L=E−1: it has 111's on the diagonal and the elimination multipliers below the diagonal (with positive signs). For the 3×33 \times 33×3 example,

L=(100210431),U=(211011002).L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ 4 & 3 & 1 \end{pmatrix}, \quad U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{pmatrix}.L=​124​013​001​​,U=​200​110​112​​.

The subdiagonal entries of LLL are exactly ℓ21=2\ell_{21} = 2ℓ21​=2, ℓ31=4\ell_{31} = 4ℓ31​=4, ℓ32=3\ell_{32} = 3ℓ32​=3 — the multipliers we computed while eliminating. You never need to form EEE and invert it by hand: record the multipliers as you go and place them under the diagonal of LLL; the upper triangular result is UUU.

Verify LU=ALU = ALU=A. The (3,3)(3,3)(3,3) entry of LULULU is 4⋅1+3⋅1+1⋅2=94\cdot 1 + 3\cdot 1 + 1\cdot 2 = 94⋅1+3⋅1+1⋅2=9, matching AAA; the rest of the product recovers AAA column by column the same way.

Why factor once? Solving Ax=bAx = bAx=b for many different right-hand sides reuses the same LLL and UUU:

  1. Forward substitution: solve Ly=bLy = bLy=b for yyy (cheap, because LLL is triangular with unit diagonal).
  2. Back-substitution: solve Ux=yUx = yUx=y for xxx.

Factoring A=LUA = LUA=LU costs O(n3)O(n^3)O(n3) for an n×nn \times nn×n matrix; each subsequent solve costs only O(n2)O(n^2)O(n2). In robotics, simulation, and least-squares pipelines where AAA is fixed and bbb changes often, this amortization is the reason LULULU is a workhorse factorization. Week 4 will also use the pivots on the diagonal of UUU: when no row exchanges occur, det⁡(A)\det(A)det(A) equals the product of those pivots.


Row Exchanges and PA=LU#

Plain elimination fails when a pivot position becomes zero (or is so small that dividing by it is numerically unsafe). You cannot form ℓ=aij/ajj\ell = a_{ij}/a_{jj}ℓ=aij​/ajj​ if ajj=0a_{jj} = 0ajj​=0. The fix is a row exchange: swap the current row with a lower row that has a nonzero entry in the pivot column, then continue.

A row exchange is left-multiplication by a permutation matrix PPP — the identity with two rows swapped (or a product of such swaps). For example, swapping rows 1 and 2 of a 2×22 \times 22×2 system uses

P=(0110).P = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}.P=(01​10​).

After the necessary permutations, elimination proceeds without division by zero and produces LLL and UUU for the permuted matrix. The general factorization is

PA=LU,PA = LU,PA=LU,

where PPP is a permutation matrix, LLL is unit lower triangular, and UUU is upper triangular. Equivalently, A=P−1LU=P⊤LUA = P^{-1} LU = P^\top LUA=P−1LU=P⊤LU (since P−1=P⊤P^{-1} = P^\topP−1=P⊤ for a permutation matrix).

When do you need PPP? Whenever a pivot is zero (or tiny) while a nonzero candidate sits below it. If an entire pivot column from the diagonal downward is zero, the matrix is singular: no sequence of row exchanges produces a full set of nonzero pivots, and Ax=bAx = bAx=b either has no solution or infinitely many. Week 5 will connect that failure mode to rank and linear dependence.

Practical note. Production libraries often use partial pivoting (swap in the largest available entry below the diagonal) and return PPP, LLL, UUU with PA=LUPA = LUPA=LU. That can reorder rows even when every pivot is already nonzero, so the printed LLL and UUU may differ from a hand calculation without row swaps — both factorizations are valid. The browser lab below builds LLL and UUU with plain elimination (no pivoting) in NumPy so the factors match the worked example above; for this AAA, P=IP = IP=I and PA=LUPA = LUPA=LU still holds.


Knowledge check#

Question 1 of 3

In A = LU, what type of matrix is L?

Unit lower triangular
Unit upper triangular
Diagonal
Orthogonal

Browser lab#

Compute an LULULU factorization with NumPy-only elimination (same AAA as the worked example) and verify PA=LUPA = LUPA=LU with P=IP = IP=I.

python · runs in browser
import numpy as np

A = np.array([[2., 1., 1.],
              [4., 3., 3.],
              [8., 7., 9.]])

n = A.shape[0]
U = A.copy()
L = np.eye(n)
P = np.eye(n)  # no row exchanges needed for this A

for k in range(n - 1):
    for i in range(k + 1, n):
        L[i, k] = U[i, k] / U[k, k]
        U[i, k:] -= L[i, k] * U[k, k:]

print("L =\n", L)
print("U =\n", U)
print("P (identity) =\n", P)
print("L @ U =\n", L @ U)
print("PA ≈ LU:", np.allclose(P @ A, L @ U))
print("LU ≈ A:", np.allclose(L @ U, A))
← Previous
Week 2: Linear Transformations and Matrices
Next →
Week 4: Determinants
On this page
  • Solving Systems by Elimination
  • Elimination as Matrix Multiplication
  • The LU Factorization
  • Row Exchanges and PA=LU
  • Knowledge check
  • Browser lab