Computed three-by-three LU decomposition (source code)

= Computed three-by-three LU decomposition
{c}
{title2=$A=LU$}

Here is an original example of <Gaussian elimination> that can be checked entirely with <integers>. Start with
$$
A=\begin{pmatrix}2&1&1\\4&5&3\\-2&8&4\end{pmatrix}.
$$
The first <pivot element> is $2$. The <elimination multipliers> are $l_{21}=4/2=2$ and $l_{31}=-2/2=-1$. Apply the <elementary row operations> $R_2\leftarrow R_2-2R_1$ and $R_3\leftarrow R_3+R_1$ to obtain
$$
A^{(1)}=\begin{pmatrix}2&1&1\\0&3&1\\0&9&5\end{pmatrix}.
$$
Now the second <pivot element> is $3$, and $l_{32}=9/3=3$. The <elementary row operation> $R_3\leftarrow R_3-3R_2$ gives
$$
U=\begin{pmatrix}2&1&1\\0&3&1\\0&0&2\end{pmatrix},\qquad L=\begin{pmatrix}1&0&0\\2&1&0\\-1&3&1\end{pmatrix},\qquad LU=A.
$$
Importantly, $l_{32}$ comes from the current reduced <matrix>, not the original entry $a_{32}=8$. To reconstruct $A$ from $U$, its second row is twice the first row of $U$ plus the second; its third row is minus the first row of $U$ plus three times the second plus the third. These are exactly the coefficients in the <lower triangular matrix> $L$.

\Image[/lu-elimination-structure.png]
{title=<Gaussian elimination> turns a three-by-three <matrix> into an <upper triangular matrix>, while <elimination multipliers> are stored in a <lower triangular matrix>}

The unpivoted calculation here illustrates the structure of <LU decomposition>; applying <partial pivoting> to this particular $A$ would choose a different first row and different factors. Both procedures can represent the same <linear system> when their <permutation matrices> are handled consistently.