import numpy as np
import matplotlib.pyplot as plt
try:
import executable_engineering as exe
except ImportError:
%pip install -q executable_engineering
import executable_engineering as exeThe Need for Pivoting¶
The order of equations (and therefore rows in the matrix) is mathematically arbitrary, but the physical order in memory can break Gaussian Elimination.
For example, a system with the following augmented matrix works perfectly with our standard GE algorithm:
But the exact same system, simply reordered, will fail:
Because the pivot element in the first row is 0, calculating the multiplier results in a division by zero!
The remedy is to pivot (swap) row 1 with another row to put a non-zero element on the diagonal.
The Permutation Matrix¶
Swapping rows in matrix algebra is achieved via a permutation matrix (which is simply a row-swapped identity matrix ).
To mathematically swap rows 3 and 1 of a matrix, we multiply it by:
Roundoff Error and Small Pivots¶
Even if the pivot isn’t exactly 0, a very small pivot element causes catastrophic roundoff error.
Consider a matrix where the top-left element is some incredibly small number :
After the first pass of Gaussian Elimination, the matrix becomes:
We can immediately see the danger as . The terms become infinitely massive, completely dominating and erasing the true values of the other coefficients due to floating-point truncation (roundoff error).
This motivates our desire to have the largest possible numbers on the diagonal!
Diagonal Dominance¶
A matrix is said to be diagonally dominant if the absolute value of each diagonal element is strictly larger than the sum of the absolute values of the other elements in that row.
Which of these is diagonally dominant?
A) $$
$$
B) $$
$$
(Answer: Matrix B is diagonally dominant! Notice how Matrix A is just Matrix B without row-pivoting. By swapping the rows of A, we can achieve diagonal dominance!)
The Importance of Diagonal Dominance¶
It can be mathematically proven that if a matrix is diagonally dominant, it will never require pivoting during Gaussian Elimination, and it is inherently immune to the catastrophic roundoff errors shown above.
Diagonal dominance contributes broadly to numerical stability. It is a critical criteria for matrix factorization methods and ensures the rapid convergence of iterative methods!