Pivoting reorders rows (and sometimes columns) to avoid division by zero and minimize round-off error. Partial pivoting, swapping rows to use the largest pivot, is essential for numerical stability.
The Problem¶
Gaussian elimination fails if a pivot element . Even when not zero, small pivots cause problems: division by small numbers amplifies errors and the algorithm becomes unstable.
Partial Pivoting¶
At each step , find the largest element in the current column (below the diagonal) and swap rows before eliminating.
Algorithm 1 (Gaussian Elimination with Partial Pivoting)
Input: ,
Output: Upper triangular , modified , permutation record
for :
Find
Swap rows and in and
for :
for :
PA = LU Decomposition¶
With pivoting, the factorization becomes:
where is a permutation matrix that records the row swaps.
To solve :
Apply permutation:
Forward solve:
Back solve:
Example 1 (Why Pivoting Matters)
Consider in 3-digit arithmetic:
Without pivoting: the multiplier is . The elimination produces , but in 3-digit arithmetic this is rounded to -10000, and the subsequent back substitution gives and . The true solution is , .
With pivoting: swap the rows first:
Now the multiplier is , which is safe. The result is accurate even in limited precision.
Types of Pivoting¶
| Strategy | Description | Cost |
|---|---|---|
| Partial pivoting | Swap rows to get largest pivot in column | comparisons |
| Complete pivoting | Swap both rows and columns | comparisons |
| Scaled pivoting | Account for row scaling before choosing pivot |
Partial pivoting is the standard choice: the overhead is comparisons, negligible compared to elimination, and it is sufficient for nearly all practical problems.
Remark 1 (Pivoting in Practice)
All standard libraries (NumPy, SciPy, LAPACK) use partial pivoting by default.
When you call scipy.linalg.solve(A, b) or scipy.linalg.lu(A), partial
pivoting is applied automatically.
Stability of Gaussian Elimination: growth factors for random matrices and the structure of LU factors with partial pivoting.