Two previous examples of LU factorizations were given. I found one more to be the key to understanding how to implement this as a matlab algorithm, required for our problem set.

A matrix that contains both pivots and elementary matrix operations is

\label{eqn:luAlgorithm:20}
M=
\begin{bmatrix}
0 & 0 & 2 & 1 \\
0 & 0 & 1 & 1 \\
2 & 0 & 2 & 0 \\
1 & 1 & 1 & 1
\end{bmatrix}

Our objective is to apply a sequence of row permutations or elementary row operations to $$M$$ that put $$M$$ into upper triangular form. At the same time we wish to track the all the inverse operations. When no permutations were required to produce $$U$$, then we end up with a factorization $$M = L’ U$$ where $$L’$$ is lower triangular.

Let’s express the row operations that we apply to $$M$$ as

\label{eqn:luAlgorithm:40}
U =
L_k^{-1}
L_{k-1}^{-1} \cdots
L_2^{-1}
L_1^{-1}
M,

with

\label{eqn:luAlgorithm:60}
L’ = L_0 L_1 L_2 \cdots L_{k-1} L_k

Here $$L_0 = I$$, the identity matrix, and $$L_i^{-1}$$ is either a permutation matrix interchanging two rows of the identity matrix, or it is an elementary row operation encoding the operation $$r_j \rightarrow r_j – M r_i$$, where $$r_i$$ is the pivot row, and $$r_j, j > i$$ are the rows that we are applying the Gaussian elimination operations to.

For our example matrix, we see that we cannot use the $$M_{1 1}$$ as the pivot element since it is zero. In general, for numeric stability, we wish to use the row with the biggest absolute value in the column that we are operating on. In this case that is row 3. Our first row operation is therefore a $$1,3$$ permutation

\label{eqn:luAlgorithm:80}
L_1^{-1} =
\begin{bmatrix}
0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix},

which gives us

\label{eqn:luAlgorithm:100}
M \rightarrow
L_1^{-1}
M
=
\begin{bmatrix}
0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
0 & 0 & 2 & 1 \\
0 & 0 & 1 & 1 \\
2 & 0 & 2 & 0 \\
1 & 1 & 1 & 1 \\
\end{bmatrix}
=
\begin{bmatrix}
2 & 0 & 2 & 0 \\
0 & 0 & 1 & 1 \\
0 & 0 & 2 & 1 \\
1 & 1 & 1 & 1 \\
\end{bmatrix}.

Computationally, we do not wish to actually do a matrix multiplication to achieve this permutation. Instead we want to just swap the two rows in question.

The inverse of this operation is the same permutation, so for $$L’$$ we compute

\label{eqn:luAlgorithm:120}
L’ \rightarrow L_0 L_1 = L_1.

As before, we don’t wish to do a matrix operation. Since we have applied the permutation matrix from the right, it results in an exchange of columns $$1,3$$ of our $$L_0$$ matrix (which happens to be identity at this point). We can implement that matrix operation as a column exchange directly using submatrix notation.

We now proceed down the column, doing all the non-zero row elimination operations required. In this case, we have only one

\label{eqn:luAlgorithm:140}
r_4 \rightarrow r_4 – \frac{1}{2} r_1.

This has the matrix form

\label{eqn:luAlgorithm:160}
L_2^{-1} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
-1/2 & 0 & 0 & 1 \\
\end{bmatrix}.

The next stage of the $$U$$ computation is

\label{eqn:luAlgorithm:180}
M
\rightarrow L_2^{-1} L_1^{-1} M
=
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
-1/2 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
2 & 0 & 2 & 0 \\
0 & 0 & 1 & 1 \\
0 & 0 & 2 & 1 \\
1 & 1 & 1 & 1 \\
\end{bmatrix}
=
\begin{bmatrix}
2 & 0 & 2 & 0 \\
0 & 0 & 1 & 1 \\
0 & 0 & 2 & 1 \\
0 & 1 & 0 & 1 \\
\end{bmatrix}.

Again, we do not wish to do this operation as a matrix operation. Instead we act directly on the rows in question with \ref{eqn:luAlgorithm:140}.

Note that the inverse of this matrix operation is very simple. We’ve subtracted $$r_1/2$$ from $$r_4$$, so to invert this we have only to add back $$r_1/2$$. That is

\label{eqn:luAlgorithm:200}
L_2
=
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
1/2 & 0 & 0 & 1 \\
\end{bmatrix}.

Observe that when we apply this from the right to $$L_0 L_1 \rightarrow L_0 L_1 L_2$$, the interpretation is a column operation

\label{eqn:luAlgorithm:220}
c_1 \rightarrow c_1 + m c_4,

In general, if we apply the row operation

\label{eqn:luAlgorithm:240}
r_j \rightarrow r_j – m r_i,

to the current state of our matrix $$U$$, then we must apply the operation

\label{eqn:luAlgorithm:260}
r_i \rightarrow r_i + m r_j,

to the current state of our matrix $$L’$$.

We are now ready to move on to reduction of column 2. We will have only a permutation operation

\label{eqn:luAlgorithm:280}
L_3 =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 \\
\end{bmatrix},

so we apply a $$2,4$$ row interchange to U, and a $$2,4$$ column interchange to $$L’$$. This gives us

\label{eqn:luAlgorithm:300}
M \rightarrow
\begin{bmatrix}
2 & 0 & 2 & 0 \\
0 & 1 & 0 & 1 \\
0 & 0 & 2 & 1 \\
0 & 0 & 1 & 1 \\
\end{bmatrix}.

Our final operation is a regular row operation

\label{eqn:luAlgorithm:320}
r_4 \rightarrow r_4 – \inv{2} r_3,

with matrix
\label{eqn:luAlgorithm:340}
L_4^{-1} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & -1/2 & 1 \\
\end{bmatrix}

We can also track all the permutations we have performed, which in this case was

\label{eqn:luAlgorithm:360}
P = L_3 L_1 I.

This should also be computed by performing row interchanges, not matrix multiplication.

Now should we wish to solve the system

\label{eqn:luAlgorithm:380}
M \Bx = L’ U \Bx = \Bb,

we can equivalently solve

\label{eqn:luAlgorithm:400}
P L’ U \Bx = P \Bb,

To do this let $$\By = U \Bx$$, so that we wish to solve

\label{eqn:luAlgorithm:420}
P L’ \By = P \Bb.

The matrix $$L = P L’$$ is lower triangular, as $$P$$ contained all the permutations that we applied along the way (FIXME: this is a statement, not a proof, and not obvious).

We can solve the system

\label{eqn:luAlgorithm:440}
L \By = P \Bb,

using forward substitution. That leaves us to solve the upper triangular system

\label{eqn:luAlgorithm:460}
\By = U \Bx,

which now requires only back substitution.