Gaussian Elimination
Gaussian elimination transforms a matrix into row echelon form, which is an upper triangular form where:
- All nonzero rows are above any rows of all zeros.
- The leading coefficient (also called the pivot) of a nonzero row is always to the right of the leading coefficient of the row above it.
- The entries below each pivot are zero.
It's a common method for solving linear systems of equations.
This is accomplished by performing three types of operations on rows, which transform the system of linear equations into a simpler system with the same solutions:
- Row can be replaced by where is any non-zero constant.
- Row can be replaced with where is any non-zero constant.
- Row and row can be swapped.
There are a lot more details but that's the gist of it. Here, we'll talk about some stragies for improving the numerical stability of this algorithm.
The first non-zero entry in any row is called a pivot. When considering Gaussian elimination purely symbolicly without concern for numerical stability, we swap rows only when necessary to ensure that the pivot is also the last non-zero value in its column. However, it's sometimes advantageous to do so for numerical stability, because it helps avoid dividing relatively large numbers by very small numbers, which is problematic for floating point computation on computers.
We use partial pivoting to help reduce this. Before each round of eliminating values below a pivot, we first see which row in the submatrix (the matrix to the right and below the pivot) has the leading entry with the largest magnitude, and if it's not the pivot row, we swap it with the pivot row and then proceed with elimination.
A slight variation is scaled partial pivoting. Here, we account for the small divisor effect on the other columns too by first picking a scaling value for each row, which is the entry in each row that has the largest magnitude, dividing each rows leading value by its respective scaling factor, and then swapping the pivot row for the row with the largest scaled leading value (if it's not already the pivot row.)
LU Factorization
Solving linear systems of the form can be computationally expensive - it requires operations for a matrix with rows and columns. If we need to solve for multiple vectors we can save computation by first factoring into the form (which is operations) and then solving for given any which is now just operations. For even moderately large values of this leads to a giant reduction in cost.
When doing ‑factorization, you write
where is lower triangular (with 1’s on the diagonal) and is upper triangular. The multipliers used during Gaussian elimination become the entries of . In other words, we perform Gaussian elimination as usual to get but we also leave breadcrumbs of which operations we used to do this to get
We start with as the identity matrix.
Let's say our pivot is at and we want to eliminate the entry at We find the multiplier such that
and then we record that in as
3×3 example:
Suppose
First, Eliminate below the first pivot ():
- Multiplier for row 2:
- Multiplier for row 3:
Apply:
You get
Next, Eliminate below the second pivot ():
- Multiplier for row 3:
Apply:
This yields the final upper triangular matrix
Finally, Collect the multipliers into (with 1’s on the diagonal):
We can verify:
Now we'll go over how to solve for an unknown given
Given
Let
We solve by first solving :
Row 1:
Row 2:
Row 3:
Thus
Next solve by back‑substitution:
Row 3:
Row 2:
Row 1:
Hence
You can verify :