Partial Pivoting
Partial pivoting is a row-swapping rule for Gaussian elimination. Before clearing each column, swap rows so the entry with the largest absolute value on or below the diagonal becomes the pivot. Every multiplier then has absolute value at most 1, which keeps round-off error from growing.
Before this lesson: Gaussian Elimination, Floating-Point Arithmetic and Loss of Significance
Why a small pivot causes trouble
In Gaussian elimination, the pivot is the entry you divide by to clear the entries below it. The multiplier for row i is m = (entry to clear) ÷ (pivot). If the pivot is tiny, m is huge.
A huge multiplier makes the new row almost entirely a copy of the pivot row, scaled up. In exact arithmetic that is fine. On a computer, each result is rounded to a fixed number of digits, so the small numbers in the original row get rounded away. The information they carried is lost.
Partial pivoting fixes this cheaply. In each column, look down from the diagonal, find the entry with the largest absolute value and swap its row into the pivot position. Swapping two equations never changes the solution, and now every multiplier satisfies |m| ≤ 1.
Partial pivoting algorithm
For an n × n system written as an augmented matrix, repeat these steps for each column k = 1, 2, …, n − 1:
- Look at the entries in column k from row k down to row n.
- Find the row p with the largest absolute value, |aₚₖ| = max |aᵢₖ| for i ≥ k.
- If p ≠ k, swap rows p and k (the whole row, including the right-hand side).
- For each row i below k, find mᵢₖ = aᵢₖ / aₖₖ and replace row i with row i − mᵢₖ · row k.
Then solve the upper triangular system by back substitution. Because the pivot is the largest entry in its column,
|m_{ik}| = \dfrac{|a_{ik}|}{|a_{kk}|} \le 1If every candidate in column k is 0, the matrix is singular and the system has no unique solution.
Partial pivoting examples
Examples 1 and 2 use 4-digit rounding arithmetic: after every operation, the result is rounded to 4 significant digits (see floating-point arithmetic). The arrow → means “rounds to.” Examples 3–5 use exact fractions.
Example 1: Elimination without pivoting
Solve the system below with 4-digit rounding and no row swaps. The exact solution is x = 10, y = 1.
\begin{aligned} 0.0004x + 1.402y &= 1.406 \\ 0.4003x - 1.502y &= 2.501 \end{aligned}m = \dfrac{0.4003}{0.0004} = 1000.75 \to 1001Multiplier for row 2, using the tiny pivot 0.0004.
1001(1.402) = 1403.402 \to 1403
Multiply the pivot row’s y-coefficient and round.
-1.502 - 1403 = -1404.502 \to -1405
New y-coefficient in row 2.
1001(1.406) = 1407.406 \to 1407
Multiply the pivot row’s right side and round.
2.501 - 1407 = -1404.499 \to -1404
New right side in row 2.
y = \dfrac{-1404}{-1405} = 0.999288\ldots \to 0.9993Solve row 2 for y.
1.402(0.9993) = 1.4010186 \to 1.401
Back-substitute into row 1.
1.406 - 1.401 = 0.005
Subtract nearly equal numbers: only one digit survives (see loss of significance).
x = \dfrac{0.005}{0.0004} = 12.5Divide by the pivot.
Answer: x = 12.5 and y = 0.9993. The value of x is off by 2.5, a 25% relative error. The multiplier 1001 swamped the −1.502 and 2.501 in row 2, and the tiny pivot then magnified the leftover error in x.
Example 2: The same system with partial pivoting
Solve the system from Example 1 again with 4-digit rounding, this time with partial pivoting.
|0.4003| \gt |0.0004|
Compare the candidates in column 1.
\begin{aligned} 0.4003x - 1.502y &= 2.501 \\ 0.0004x + 1.402y &= 1.406 \end{aligned}Swap rows 1 and 2.
m = \dfrac{0.0004}{0.4003} = 0.000999250\ldots \to 0.0009993Multiplier for the new row 2; now |m| ≤ 1.
0.0009993(-1.502) = -0.0015009\ldots \to -0.001501
Multiply the pivot row’s y-coefficient and round.
1.402 - (-0.001501) = 1.403501 \to 1.404
New y-coefficient in row 2.
0.0009993(2.501) = 0.0024992\ldots \to 0.002499
Multiply the pivot row’s right side and round.
1.406 - 0.002499 = 1.403501 \to 1.404
New right side in row 2.
y = \dfrac{1.404}{1.404} = 1Solve row 2 for y.
2.501 + 1.502(1) = 4.003
Back-substitute into row 1: 0.4003x = 2.501 + 1.502y.
x = \dfrac{4.003}{0.4003} = 10Divide by the pivot.
Answer: x = 10 and y = 1, the exact solution. Same arithmetic, same number of digits; only the row order changed.
Example 3: A 3 × 3 system with two row swaps
Solve the system with partial pivoting, using exact fractions.
\begin{aligned} x + 2y - z &= -3 \\ 4x + 2y + 2z &= 6 \\ -2x + 5y + z &= -5 \end{aligned}\max(|1|, |4|, |-2|) = 4
Column 1: the largest candidate is in row 2.
\left[\begin{array}{rrr|r} 4 & 2 & 2 & 6 \\ 1 & 2 & -1 & -3 \\ -2 & 5 & 1 & -5 \end{array}\right]Swap rows 1 and 2.
m_{21} = \dfrac{1}{4},\quad m_{31} = \dfrac{-2}{4} = -\dfrac{1}{2}Multipliers for rows 2 and 3.
R_2 - \tfrac{1}{4}R_1 = \begin{bmatrix} 0 & 1.5 & -1.5 & -4.5 \end{bmatrix}Clear row 2: 2 − 0.5 = 1.5, −1 − 0.5 = −1.5, −3 − 1.5 = −4.5.
R_3 + \tfrac{1}{2}R_1 = \begin{bmatrix} 0 & 6 & 2 & -2 \end{bmatrix}Clear row 3: 5 + 1 = 6, 1 + 1 = 2, −5 + 3 = −2.
\max(|1.5|, |6|) = 6
Column 2: the largest candidate is in row 3.
\left[\begin{array}{rrr|r} 4 & 2 & 2 & 6 \\ 0 & 6 & 2 & -2 \\ 0 & 1.5 & -1.5 & -4.5 \end{array}\right]Swap rows 2 and 3.
m_{32} = \dfrac{1.5}{6} = \dfrac{1}{4}Multiplier for row 3.
R_3 - \tfrac{1}{4}R_2 = \begin{bmatrix} 0 & 0 & -2 & -4 \end{bmatrix}Clear row 3: −1.5 − 0.5 = −2 and −4.5 + 0.5 = −4.
z = \dfrac{-4}{-2} = 2Solve the last row.
6y + 2(2) = -2 \Rightarrow 6y = -6 \Rightarrow y = -1
Back-substitute into row 2.
4x + 2(-1) + 2(2) = 6 \Rightarrow 4x = 4 \Rightarrow x = 1
Back-substitute into row 1.
Answer: (x, y, z) = (1, −1, 2). Check in the original second equation: 4(1) + 2(−1) + 2(2) = 6.
Example 4: Writing PA = LU
Record the row swaps and multipliers from Example 3 as a factorization PA = LU (see LU decomposition). P is a permutation matrix that lists the rows of A in their final order.
\text{final order: } (4, 2, 2),\ (-2, 5, 1),\ (1, 2, -1)After both swaps the rows are original rows 2, 3, 1.
P = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{bmatrix}Row i of P picks that original row.
L = \begin{bmatrix} 1 & 0 & 0 \\ -\tfrac{1}{2} & 1 & 0 \\ \tfrac{1}{4} & \tfrac{1}{4} & 1 \end{bmatrix}Multipliers move with their rows: −1/2 belongs to (−2, 5, 1), now row 2.
U = \begin{bmatrix} 4 & 2 & 2 \\ 0 & 6 & 2 \\ 0 & 0 & -2 \end{bmatrix}The triangular matrix from elimination.
-\tfrac{1}{2}(4, 2, 2) + (0, 6, 2) = (-2, 5, 1)Check row 2 of LU against row 2 of PA.
\tfrac{1}{4}(4, 2, 2) + \tfrac{1}{4}(0, 6, 2) + (0, 0, -2) = (1, 2, -1)Check row 3 of LU against row 3 of PA.
Answer: PA = LU with the P, L and U above. To solve Ax = b for a new b, reorder b with P, then solve Ly = Pb and Ux = y.
Example 5: A trail mix blend (word problem)
A store blends 10 kg of trail mix from peanuts ($3/kg), raisins ($5/kg) and chocolate chips ($8/kg). The ingredients cost $46 in total, and the peanuts weigh as much as the raisins and chips combined. Find the kilograms of each, using partial pivoting.
\begin{aligned} x + y + z &= 10 \\ 3x + 5y + 8z &= 46 \\ x - y - z &= 0 \end{aligned}Let x, y, z be kg of peanuts, raisins and chips.
\max(|1|, |3|, |1|) = 3
Column 1: swap rows 1 and 2.
R_2 - \tfrac{1}{3}R_1 = \begin{bmatrix} 0 & -\tfrac{2}{3} & -\tfrac{5}{3} & -\tfrac{16}{3} \end{bmatrix}Clear the old row 1 with m = 1/3: 1 − 5/3, 1 − 8/3, 10 − 46/3.
R_3 - \tfrac{1}{3}R_1 = \begin{bmatrix} 0 & -\tfrac{8}{3} & -\tfrac{11}{3} & -\tfrac{46}{3} \end{bmatrix}Clear row 3 with m = 1/3: −1 − 5/3, −1 − 8/3, 0 − 46/3.
\max\left(\left|-\tfrac{2}{3}\right|, \left|-\tfrac{8}{3}\right|\right) = \tfrac{8}{3}Column 2: swap rows 2 and 3.
m_{32} = \dfrac{-2/3}{-8/3} = \dfrac{1}{4}Multiplier for the last row.
-\tfrac{5}{3} - \tfrac{1}{4}\left(-\tfrac{11}{3}\right) = -\tfrac{20}{12} + \tfrac{11}{12} = -\tfrac{3}{4}New z-coefficient (see adding and subtracting fractions).
-\tfrac{16}{3} - \tfrac{1}{4}\left(-\tfrac{46}{3}\right) = -\tfrac{64}{12} + \tfrac{46}{12} = -\tfrac{3}{2}New right side.
z = \dfrac{-3/2}{-3/4} = 2Solve the last row.
-\tfrac{8}{3}y - \tfrac{11}{3}(2) = -\tfrac{46}{3} \Rightarrow -8y - 22 = -46 \Rightarrow y = 3Back-substitute; multiply through by 3.
3x + 5(3) + 8(2) = 46 \Rightarrow 3x = 15 \Rightarrow x = 5
Back-substitute into the pivot row.
Answer: 5 kg of peanuts, 3 kg of raisins and 2 kg of chocolate chips. Check: 5 + 3 + 2 = 10 and 15 + 15 + 16 = 46.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Choosing the largest entry instead of the largest absolute value | Keeping 1 as the pivot over −2 in column (1, −2) | Compare |aᵢₖ|; −2 wins because |−2| = 2 > 1. |
| Searching above the diagonal | In column 2, comparing with the entry in row 1 | Only rows k through n are candidates; rows above are finished. |
| Swapping only the coefficients | Moving the left side of a row but leaving its right-hand side behind | Swap the whole augmented row. |
| Forgetting to move multipliers when writing L | Leaving m = 1/4 in row 2 of L after a later swap moved its row | When rows swap, swap the multipliers already stored in those rows. |
| Thinking pivoting changes the answer | Expecting a different solution after a swap | Swapping equations keeps the same solution; it only changes the rounding error. |
Related methods
Scaled partial pivoting
If one row has much larger coefficients than another, plain partial pivoting can be fooled. Scaled partial pivoting divides each candidate by sᵢ, the largest absolute value in its own row, and picks the row with the largest ratio |aᵢₖ| / sᵢ.
Complete pivoting
Complete pivoting searches the whole remaining submatrix for the largest entry and swaps both rows and columns. It is safer in rare cases but costs much more searching, so partial pivoting is the standard choice in software such as LAPACK.
When no swaps are needed
If a matrix is strictly diagonally dominant by columns (each diagonal entry is larger in absolute value than the sum of the others in its column), partial pivoting never swaps. Such matrices also suit iterative methods like the Jacobi method, the next lesson.
Practice problems
- Column 1 of a matrix has entries 2, −7 and 5 in rows 1, 2 and 3. Which row becomes the pivot row?
- Solve with partial pivoting: x + 3y = 11 and 2x + y = 7.
- Solve with partial pivoting: 2x + 4y − 2z = 12, 6x + 3y = 12 and −3x + 6y + 4z = 5.
- A matrix has rows (3, 900) and (2, 1). Which row does partial pivoting choose in column 1? Which row does scaled partial pivoting choose?
- Use 3-digit rounding to solve 0.0001x + y = 1 and x + y = 3, first without pivoting and then with partial pivoting. (The exact solution is x ≈ 2.0002, y ≈ 0.9998.)
- Find P, L and U with PA = LU for A = \begin{bmatrix} 2 & 1 \\ 8 & 6 \end{bmatrix} using partial pivoting.
- Solve 2y = 4 and 3x + y = 5. Why does elimination without pivoting fail on this system as written?
- After clearing column 1, the entries in column 2 of rows 2, 3 and 4 are 0.5, −3 and 2. Which row moves into row 2?
- A coffee shop blends Kenyan beans ($14/lb) and Brazilian beans ($9/lb) into 20 lb that cost $210. Write the system with the weight equation first, then solve it with partial pivoting.
- Does partial pivoting swap any rows for A = \begin{bmatrix} 5 & 1 & 2 \\ 1 & 4 & 1 \\ 2 & 1 & 6 \end{bmatrix}?
Show answers
1.
\max(|2|, |-7|, |5|) = 7
Compare absolute values.
Answer: row 2 (the entry −7), so rows 1 and 2 are swapped
2.
2x + y = 7,\quad x + 3y = 11
Since |2| > |1|, swap the rows.
m = \dfrac{1}{2}Multiplier for the new row 2.
3 - \tfrac{1}{2}(1) = \tfrac{5}{2},\quad 11 - \tfrac{1}{2}(7) = \tfrac{15}{2}New row 2: (5/2)y = 15/2.
y = 3
Divide by 5/2.
2x + 3 = 7 \Rightarrow x = 2
Back-substitute.
Answer: x = 2, y = 3
3.
\max(|2|, |6|, |-3|) = 6
Column 1: swap rows 1 and 2.
R_2 - \tfrac{1}{3}R_1 = \begin{bmatrix} 0 & 3 & -2 & 8 \end{bmatrix}m = 2/6 = 1/3: 4 − 1, −2 − 0, 12 − 4.
R_3 + \tfrac{1}{2}R_1 = \begin{bmatrix} 0 & 7.5 & 4 & 11 \end{bmatrix}m = −3/6 = −1/2: 6 + 1.5, 4 + 0, 5 + 6.
\max(|3|, |7.5|) = 7.5
Column 2: swap rows 2 and 3.
m_{32} = \dfrac{3}{7.5} = 0.4Multiplier for the last row.
-2 - 0.4(4) = -3.6,\quad 8 - 0.4(11) = 3.6
New last row: −3.6z = 3.6.
z = -1
Divide.
7.5y + 4(-1) = 11 \Rightarrow 7.5y = 15 \Rightarrow y = 2
Back-substitute.
6x + 3(2) + 0 = 12 \Rightarrow 6x = 6 \Rightarrow x = 1
Back-substitute.
Answer: (x, y, z) = (1, 2, −1)
4.
|3| \gt |2|
Partial pivoting compares the entries alone.
\dfrac{3}{900} \approx 0.0033,\quad \dfrac{2}{2} = 1Scaled: divide by each row’s largest absolute value (900 and 2).
Answer: partial pivoting keeps row 1; scaled partial pivoting chooses row 2
5.
m = \dfrac{1}{0.0001} = 10000No pivoting: huge multiplier.
1 - 10000 = -9999 \to -10000,\quad 3 - 10000 = -9997 \to -10000
Row 2 after rounding to 3 digits.
y = 1.00,\quad 0.0001x = 1 - 1 = 0 \Rightarrow x = 0
Back-substitution loses x completely.
m = \dfrac{0.0001}{1} = 0.0001With pivoting: swap rows; tiny multiplier.
1 - 0.0001 = 0.9999 \to 1.00,\quad 1 - 0.0003 = 0.9997 \to 1.00
New row 2 after rounding.
y = 1.00,\quad x = 3 - 1.00 = 2.00
Back-substitute.
Answer: without pivoting x = 0, y = 1.00 (x is completely wrong); with pivoting x = 2.00, y = 1.00, correct to 3 digits
6.
PA = \begin{bmatrix} 8 & 6 \\ 2 & 1 \end{bmatrix},\quad P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}Since |8| > |2|, swap the rows.
m = \dfrac{2}{8} = \dfrac{1}{4}Multiplier.
1 - \tfrac{1}{4}(6) = -\tfrac{1}{2}New entry in row 2.
Answer: L = \begin{bmatrix} 1 & 0 \\ \tfrac{1}{4} & 1 \end{bmatrix}, U = \begin{bmatrix} 8 & 6 \\ 0 & -\tfrac{1}{2} \end{bmatrix}
7.
0x + 2y = 4
The first pivot is 0, so m = 3/0 is undefined.
3x + y = 5,\quad 2y = 4
Since |3| > |0|, swap the rows; the system is already triangular.
y = 2,\quad 3x = 5 - 2 = 3 \Rightarrow x = 1
Back-substitute.
Answer: x = 1, y = 2; without a swap the first step divides by 0
8.
\max(|0.5|, |-3|, |2|) = 3
Compare absolute values in rows 2–4.
Answer: row 3 (the entry −3) is swapped into row 2
9.
x + y = 20,\quad 14x + 9y = 210
x = lb Kenyan, y = lb Brazilian.
|14| \gt |1| \Rightarrow m = \dfrac{1}{14}Swap the rows; multiplier for the weight equation.
1 - \tfrac{9}{14} = \tfrac{5}{14},\quad 20 - \tfrac{210}{14} = 5New row 2: (5/14)y = 5.
y = 14
Divide by 5/14.
14x + 9(14) = 210 \Rightarrow 14x = 84 \Rightarrow x = 6
Back-substitute.
Answer: 6 lb of Kenyan and 14 lb of Brazilian beans
10.
\max(|5|, |1|, |2|) = 5
Column 1: the pivot is already in row 1.
R_2 - 0.2R_1 = (0, 3.8, 0.6),\quad R_3 - 0.4R_1 = (0, 0.6, 5.2)
Clear column 1.
\max(|3.8|, |0.6|) = 3.8
Column 2: the pivot is already in row 2.
Answer: no swaps; A is strictly diagonally dominant by columns, so the diagonal entry always wins
Partial pivoting FAQ
What is partial pivoting?
It is the rule of swapping rows during Gaussian elimination so that, in each column, the entry with the largest absolute value on or below the diagonal becomes the pivot.
Why is partial pivoting used in Gaussian elimination?
It avoids dividing by zero and keeps every multiplier at most 1 in absolute value, so rounding errors are not magnified. Without it, a small pivot can ruin the answer even for a well-behaved system.
What is the difference between partial and complete pivoting?
Partial pivoting searches one column and swaps rows. Complete pivoting searches the whole remaining submatrix and swaps rows and columns, which is more work and rarely needed.
Does partial pivoting change the solution?
No. Swapping two equations gives an equivalent system with the same solution. In exact arithmetic you get the same answer; in rounded arithmetic you get a more accurate one.
Summary
- Partial pivoting swaps rows so the pivot is the largest entry, in absolute value, on or below the diagonal of its column.
- It keeps every multiplier at most 1 in absolute value, which controls round-off error.
- Swap the whole augmented row, and search only rows k through n.
- The swaps and multipliers give a factorization PA = LU.
- Scaled partial pivoting compares |aᵢₖ| / sᵢ; complete pivoting also swaps columns.
Previous lesson: Gaussian Quadrature
Next lesson: Jacobi Method
Back to the Numerical Methods Index