On this page
On paper, with exact fractions, Gaussian elimination solves any system Ax = b that has a unique answer, swapping rows only when a pivot is zero. On a computer it can fail badly, even on a 2×2 system, because of one division. Partial pivoting fixes it, which is why software factorises PA = LU, not A = LU. New to A = LU? Start with our worked guide to LU decomposition.
Why does a tiny pivot ruin Gaussian elimination?
In double precision, the gap between 1 and the next larger number is 2⁻⁵², about 2.2 × 10⁻¹⁶ (NumPy documentation). Anything much smaller, added to 1, disappears; see why 0.1 + 0.2 ≠ 0.3 for the same effect.
Take the classic example with 10⁻²⁰ in the corner:
10⁻²⁰ x₁ + x₂ = 1
x₁ + x₂ = 2
The true answer is x₁ ≈ 1 and x₂ ≈ 1. Eliminate without swapping. The pivot is 10⁻²⁰, so the multiplier is 10²⁰. Subtracting 10²⁰ times row 1 from row 2 gives (1 − 10²⁰) x₂ = 2 − 10²⁰. Both sides round to −10²⁰, so x₂ = 1, which is fine. Back-substitute: x₁ = (1 − x₂)/10⁻²⁰ = 0. It should be 1. The huge multiplier wiped out the 1 and the 2 in row 2, and dividing by the tiny pivot made the loss total.
David Bindel's Cornell lecture notes describe the same failure for rows (δ, 1) and (1, 1): "we ended up subtracting a huge multiple of the first row from the second row because δ is close to zero", so L and U become enormous even though A is small (Bindel, CS 4220 notes, 2023).
A truly sensitive matrix is a different problem, measured by its condition number.
How does partial pivoting fix it?
Before eliminating in each column, look at the entries on and below the diagonal, and swap the row with the largest absolute value into the pivot position (Chasnov, Numerical Methods, LibreTexts/03%3A_System_of_Equations/3.03%3A_Partial_Pivoting)).
Put x₁ + x₂ = 2 first. Now the multiplier is 10⁻²⁰, row 2 becomes (1 − 10⁻²⁰) x₂ = 1 − 2 × 10⁻²⁰, which rounds to x₂ = 1, and x₁ = 2 − 1 = 1. Both correct.
With the largest pivot in each column, every multiplier has size at most 1, so no row is scaled by a huge number before being subtracted. Bindel's notes add that pathological matrices exist where the entries of U still grow exponentially with n, but "these examples are extremely uncommon in practice" (Bindel).
What does PA = LU mean?
Each row swap is multiplication by a permutation matrix, the identity with its rows reordered. Collect the swaps into one matrix P and you get PA = LU, with L unit lower triangular and U upper triangular; every square matrix has such a factorisation (LU decomposition, Wikipedia). To solve Ax = b, solve Ly = Pb by forward substitution, then Ux = y by back substitution.
SciPy's scipy.linalg.lu returns factors with A = PLU (SciPy documentation), so its P is the transpose of the P in PA = LU.
Worked example: a 3×3 LU factorisation with partial pivoting
Factorise the matrix A with rows (1, 2, 1), (3, 8, 1), (0, 4, 1).
Column 1 holds 1, 3, 0. The largest is 3, in row 2, so swap rows 1 and 2: (3, 8, 1), (1, 2, 1), (0, 4, 1).
Multipliers: l₂₁ = 1/3 and l₃₁ = 0. Row 2 becomes (1, 2, 1) − (1/3)(3, 8, 1) = (0, −2/3, 2/3). Row 3 stays (0, 4, 1).
Column 2 holds −2/3 and 4 below the diagonal. The larger in size is 4, so swap rows 2 and 3, and swap their stored multipliers too: row 2 now carries 0, row 3 carries 1/3.
l₃₂ = (−2/3)/4 = −1/6. Row 3 becomes (0, −2/3, 2/3) + (1/6)(0, 4, 1) = (0, 0, 5/6).
The result:
P has rows (0, 1, 0), (0, 0, 1), (1, 0, 0): the final order is original rows 2, 3, 1.
L has rows (1, 0, 0), (0, 1, 0), (1/3, −1/6, 1).
U has rows (3, 8, 1), (0, 4, 1), (0, 0, 5/6).
Check: the third row of LU is (1/3)(3, 8, 1) − (1/6)(0, 4, 1) + (0, 0, 5/6) = (1, 2, 1), row 1 of A, exactly where P put it.
How do you check a pivoting answer?
Pick the largest absolute value, not the largest signed value.
Every entry of L below the diagonal has size at most 1.
P is the identity with its rows in the final order.
Multiply out one row of LU and compare it with PA.
Solve Ly = Pb, not Ly = b.
If row reduction feels shaky, the Fermi Concept Library has a lesson for every concept in mathematics, and the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning.



