lacunary - Mathnotes

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 ri can be replaced by λri, where λ is any non-zero constant.
  • Row ri can be replaced with ri+λrj, where λ is any non-zero constant.
  • Row ri and row rj 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 Ax=b can be computationally expensive - it requires O(n3/3) operations for a matrix with n rows and n columns. If we need to solve for multiple vectors b, we can save computation by first factoring A into the form A=LU, (which is O(n3/3) operations) and then solving for x given any b, which is now just O(2n2) operations. For even moderately large values of n this leads to a giant reduction in cost.

When doing LU‑factorization, you write

A=LU

where L is lower triangular (with 1’s on the diagonal) and U is upper triangular. The multipliers used during Gaussian elimination become the entries of L. In other words, we perform Gaussian elimination as usual to get U, but we also leave breadcrumbs of which operations we used to do this to get L.

We start with L as the identity matrix.

Let's say our pivot is at Ej,1 and we want to eliminate the entry at Ej+1,1. We find the multiplier mj+1,1 such that

Ej+1,1mj+1,1Ej,1=0

and then we record that mj+1,1 in L as Lj+1,1.

3×3 example:

Suppose

A=(211460272).

First, Eliminate below the first pivot (2):

  • Multiplier for row 2:

m21=42=2.

  • Multiplier for row 3:

m31=22=1.

Apply:

R2R2m21R1,R3R3m31R1.

You get

U(1)=(211082083).

Next, Eliminate below the second pivot (8):

  • Multiplier for row 3:

m32=88=1.

Apply:

R3R3m32R2.

This yields the final upper triangular matrix

U=(211082001).

Finally, Collect the multipliers into L (with 1’s on the diagonal):

L=(100m2110m31m321)=(100210111).

We can verify:

LU=(100210111)(211082001)=(211460272)=A.

Now we'll go over how to solve for an unknown x given b.

Given

A=(211460272),L=(100210111),U=(211082001).

Let

b=(529).

We solve LUx=b by first solving Ly=b:

Row 1:

y1=b1=5.

Row 2:

2y1+y2=b2y2=b22y1=225=12.

Row 3:

y1y2+y3=b3y3=b3+y1+y2=9+5+(12)=2.

Thus

y=(5122).

Next solve Ux=y by back‑substitution:

Row 3:

x3=y3=2.

Row 2:

8x22x3=y28x222=12x2=1.

Row 1:

2x1+x2+x3=y12x1+1+2=5x1=1.

Hence

x=(112).

You can verify Ax=b:

Ax=(211460272)(112)=(529)=b.