Let $L$ be a lower-triangular matrix ($n \times n$) and $U$ be an upper-triangular matrix (also $n \times n$).
We've discussed how to solve $Ux = y$ with backward substitution:
$$ x_i = \frac{\displaystyle y_i - \sum_{j = i+1}^n u_{ij}x_j}{u_{ii}},\quad i = n, n-1, \ldots, 2,1.$$We also discussed how to solve $Ly = b$ with forward substitution:
$$ y_i = \frac{\displaystyle b_i - \sum_{j=1}^{i-1} l_{ij} y_j }{l_{ii}}, \quad i = 1,2,\ldots,n-1,n.$$Assume that we can express $A$ as $LU$ and we want to solve $Ax=b$:
$$A x = LU x = b = L(Ux) = b.$$Recall from Lecture 9 that backward substitution requires $O(n^2)$ operations. The same is true of forward substitution.
To solve $Ax = b$ when a factorization $A = LU$ is known therefore also requires $O(n^2)$ operations.
This should be compared with Gaussian elimination with backward substitution (or worse, matrix inversion), which requires $O(n^3)$ operations.
But what if the $LU$ factorization is not known in advance? How much effort is required to compute it? The answer is $O(n^3)$ because Gaussian elimination is the means by which we $LU$-factorize, as we will see next.
Thus $LU$ factorization and Gaussian elimination are just two sides of the same coin.
Assume $A$ is an $n\times n$ matrix that can be put in upper-triangular form without row swaps (we'll deal with those next lecture).
Consider the $3\times 3$ case first
$$A = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix}$$$$ R_2 - \frac{a_{21}}{a_{11}}R_1 \to R_2$$Here $a^{(1)}_{22} = a_{22} - a_{12} \frac{a_{21}}{a_{11}}$ and $a^{(1)}_{23}= a_{23} - a_{13} \frac{a_{21}}{a_{11}}$. The question that will lead us to an $LU$ factorization is: What type of matrix does this row operation correspond to?
Recall that the goal is to express $A = LU$, so we find the inverse of the lower-triangular matrix:
$$\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} 1 & 0 & 0 \\ -a_{21}/a_{11} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} $$So, after a single step, we have found
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix}$$This is closer to a lower/upper factorization.
Next we perform the row operation $R_{3} - \frac{a_{31}}{a_{11}} R_1 \to R_3$ which corresponds to
$$\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ - a_{31}/a_{11} & 0 & 1 \end{bmatrix}\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix}$$where $a^{(1)}_{32} = a_{32} - a_{12} \frac{a_{31}}{a_{11}}$ and $a^{(1)}_{33} = a_{33} - a_{13} \frac{a_{31}}{a_{11}}$
The inverse of the lower-triangular factor can be confirmed
$$\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix}\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ - a_{31}/a_{11} & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0& 0 & 1 \end{bmatrix}$$Thus:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix}\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix}$$Combine the two row operations to yield:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix}\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix}$$which can be written as:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix}$$This brings us very close to an $LU$ factorization
For the last step, we need to perform $R_3 - \frac{a^{(1)}_{32}}{a^{(1)}_{22}} R_2 \to R_3$
$$ \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & 0 & a^{(2)}_{33} \end{bmatrix}$$where $a^{(2)}_{33} = a^{(1)}_{33} - a^{(1)}_{23} \frac{a^{(1)}_{32}}{a^{(1)}_{22}}$.
Again, you can check that the inverse of the matrix on the left is simple
$$ \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} $$so that we get:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & 0 & a^{(2)}_{33} \end{bmatrix}$$Inserting this into the existing factorization:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & a^{(1)}_{32} & a^{(1)}_{33} \end{bmatrix}$$yields:
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ a_{31}/a_{11} & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & 0 & a^{(2)}_{33} \end{bmatrix}$$The inner factors simplify and we have an LU factorization
$$\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 \\ a_{21}/a_{11} & 1 & 0 \\ a_{31}/a_{11} & a^{(1)}_{32}/a^{(1)}_{22} & 1 \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ 0 & a^{(1)}_{22} & a^{(1)}_{23} \\ 0 & 0 & a^{(2)}_{33} \end{bmatrix}$$The LU algorithm (no row interchanges)
INPUT a n x n matrix A
OUTPUT the LU factorization of A, or a message of failure
STEP 1: Set L to be the n x n identity matrix;
STEP 2: For j = 1, 2, ...,n do STEPS 3-4
STEP 3: If A(j,j) = 0
OUTPUT('LU Factorization failed')
STOP.
STEP 4: For i = j+1, j+2, ... , n do STEPS 5-6
STEP 5: Set L(i,j) = A(i,j)/A(j,j);
STEP 6: Perform row operation Ri - L(i,j)*Rj --> Ri on A;
STEP 7: OUTPUT([L,A]);