LU factorization of a matrix

matricesnumerical methods

I am trying to computer the LU factorization of the following matrix by hand. This is the first time I have tried a question like this so i am checking to see if my workings are correct, and if they need anymore detail. Thanks!

$$ A=
\left[
\begin{matrix}
2&1&3\\1&2&1\\1&2&3
\end{matrix}
\right]
$$

Finding the upper triangular matrix by reduced form

$$\left[
\begin{matrix}
2&1&3\\1&2&1\\1&2&3
\end{matrix}
\right]
R_2\rightarrow R_1-2R_2 = \left[
\begin{matrix}
2&1&3\\0&-3&1\\1&2&3
\end{matrix}
\right]\\
R_3 \rightarrow R_1-R_2 = \left[
\begin{matrix}
2&1&3\\0&-3&1\\0&-3&-3
\end{matrix}
\right] \\ R_3\rightarrow R_2-R_3 = \left[
\begin{matrix}
2&1&3\\0&-3&1\\0&0&4
\end{matrix}
\right]
$$

Then using the $k$s we used to modify each row to form the lower triangular matrix we get:

$$\left[
\begin{matrix}
1&0&0\\2&1&0\\2&1&1
\end{matrix}
\right]
$$

Therefore,

$$
\left[
\begin{matrix}
2&1&3\\1&2&1\\1&2&3
\end{matrix}
\right] = \left[
\begin{matrix}
1&0&0\\2&1&0\\2&1&1
\end{matrix}
\right]
\left[
\begin{matrix}
2&1&3\\0&-3&1\\0&0&4
\end{matrix}
\right]$$

Best Answer

This is from another answer of mine.

Suppose that

$$ A = \begin{bmatrix} 2 & 1 & 3 \\ 1 & 2 & 1 \\1 & 2 & 3 \end{bmatrix} \tag{1}$$ $$ A = LU \tag{2} $$

$$ U =A, L=I \tag{3}$$ $$\ell_{21} = \frac{u_{21}}{u_{11}} = \frac{a_{21}}{a_{11}} = \frac{1}{2} \tag{4} $$

This is where you made the mistake $$ R_{2} \to R_{2} - \frac{1}{2} R_{1} \tag{5} $$ Then we're going to subtract $\frac{1}{2}$ times the 1st row from the 2nd row $$ \begin{bmatrix} 1 & 2 & 1 \end{bmatrix} - \frac{1}{2} \cdot \begin{bmatrix} 2 & 1 & 3 \end{bmatrix} = \begin{bmatrix} 0 & \frac{3}{2} & \frac{-1}{2} \end{bmatrix} \tag{6} $$ Updating each of them $$ L= \begin{bmatrix} 1 & 0 & 0 \\ \frac{1}{2} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \tag{7} $$ $$ U = \begin{bmatrix} 2 & 1 & 3 \\ 0 & \frac{3}{2} & \frac{-1}{2} \\1 & 2 & 3 \end{bmatrix} \tag{8}$$ $$ \ell_{31} = \frac{u_{31}}{u_{11} } = \frac{1}{2} \tag{9} $$

$$ R_{3} \to R_{3} - \frac{1}{2} R_{1} \tag{10} $$ $$ R_{3} = \begin{bmatrix} 1 & 2 & 3\end{bmatrix} - \frac{1}{2} \begin{bmatrix} 2 & 1 & 3\end{bmatrix} = \begin{bmatrix} 0 & \frac{3}{2} & \frac{3}{2}\end{bmatrix} \tag{11} $$

Updating each of them $$ L= \begin{bmatrix} 1 & 0 & 0 \\ \frac{1}{2} & 1 & 0 \\ \frac{1}{2} & 0 & 1 \end{bmatrix} \tag{12} $$ $$ U = \begin{bmatrix} 2 & 1 & 3 \\ 0 & \frac{3}{2} & \frac{-1}{2} \\0 & \frac{3}{2} & \frac{3}{2} \tag{13} \end{bmatrix}$$

$$ \ell_{32} = \frac{u_{32}}{u_{22}} = \frac{\frac{3}{2}}{\frac{3}{2}} = 1 \tag{14}$$

$$ R_{3} \to R_{3} - R_{2} \tag{15} $$

$$ R_{3} = \begin{bmatrix} 0 & \frac{3}{2} & \frac{3}{2} \end{bmatrix} - \begin{bmatrix} 0& \frac{3}{2} & \frac{-1}{2} \end{bmatrix} = \begin{bmatrix} 0 &0 & 2\end{bmatrix} \tag{16}$$

Updating each of them $$ L= \begin{bmatrix} 1 & 0 & 0 \\ \frac{1}{2} & 1 & 0 \\ \frac{1}{2} & 1& 1 \end{bmatrix} \tag{17}$$ $$ U = \begin{bmatrix} 2 & 1 & 3 \\ 0 & \frac{3}{2} & \frac{-1}{2} \\0 & 0 & 2 \end{bmatrix} \tag{18} $$ It now terminates $$ A = LU $$ $$ \underbrace{\begin{bmatrix} 2 & 1 & 3 \\ 1 & 2 & 1 \\1 & 2 & 3 \end{bmatrix}}_{A} = \underbrace{\begin{bmatrix} 1 & 0 & 0 \\ \frac{1}{2} & 1 & 0 \\ \frac{1}{2} & 1& 1 \end{bmatrix} }_{L} \underbrace{\begin{bmatrix} 2 & 1 & 3 \\ 0 & \frac{3}{2} & \frac{-1}{2} \\0 & 0 & 2 \end{bmatrix}}_{U} \tag{19} $$

Just to confirm this in python

import scipy.linalg


A = scipy.array([[2 ,1,3],[1, 2, 1 ] ,[1,2,3]])
P,L,U = scipy.linalg.lu(A)

L
Out[6]: 
array([[1. , 0. , 0. ],
       [0.5, 1. , 0. ],
       [0.5, 1. , 1. ]])

U
Out[7]: 
array([[ 2. ,  1. ,  3. ],
       [ 0. ,  1.5, -0.5],
       [ 0. ,  0. ,  2. ]])