# LU factorization and partial pivoting

I have an example of LU factorization and I need to understand somethings..

I need to solve matrix A = $\begin{bmatrix}1&2&1\\2&5&3\\1&4&9\end{bmatrix}$ using LU factorization with partial pivoting , I know the first step is to factor PA = LU $$\begin{bmatrix}0&1&0\\1&0&0\\0&0&1\end{bmatrix}\begin{bmatrix}1&2&1\\2&5&3\\1&4&9\end{bmatrix}=\begin{bmatrix}2&5&3\\1&2&1\\1&4&9\end{bmatrix}$$ $$P_1 .A=P_1A$$ $$\begin{bmatrix}1&0&0\\-1/2&1&0\\-1/2&0&1\end{bmatrix}\begin{bmatrix}2&5&3\\1&2&1\\1&4&9\end{bmatrix}=\begin{bmatrix}2&5&3\\0&-1/2&-1/2\\0&3/2&15/2\end{bmatrix}$$ $$L_1.P_1A = L_1P_1A$$ now my question is how did we get $L_1$?

Here are the steps for producing our desired $$PA=LU$$ factorization using maximal partial pivoting \begin{align*} \overset{A}{\left[\begin{array}{rrr} 1 & 2 & 1 \\ 2 & 5 & 3 \\ 1 & 4 & 9 \end{array}\right]}\xrightarrow{R_1\leftrightarrow R_2}\overset{U}{\left[\begin{array}{rrr} 2 & 5 & 3 \\ 1 & 2 & 1 \\ 1 & 4 & 9 \end{array}\right]} && \overset{L}{\left[\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right]} &&\overset{P}{\left[\begin{array}{rrr} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array}\right]} \\ \xrightarrow{\begin{array}{rcrcr}R_2&-&\color{blue}{\frac{1}{2}}\cdot R_1 &\to& R_2 \\ R_3 &-& \color{red}{\frac{1}{2}}\cdot R_1 &\to& R_3\end{array}}\left[\begin{array}{rrr} 2 & 5 & 3 \\ 0 & -\frac{1}{2} & -\frac{1}{2} \\ 0 & \frac{3}{2} & \frac{15}{2} \end{array}\right] && \left[\begin{array}{rrr} 1 & 0 & 0 \\ \color{blue}{\frac{1}{2}} & 1 & 0 \\ \color{red}{\frac{1}{2}} & 0 & 1 \end{array}\right] && \left[\begin{array}{rrr} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array}\right] \\ \xrightarrow{R_2\leftrightarrow R_3}\left[\begin{array}{rrr} 2 & 5 & 3 \\ 0 & \frac{3}{2} & \frac{15}{2} \\ 0 & -\frac{1}{2} & -\frac{1}{2} \end{array}\right] && \left[\begin{array}{rrr} 1 & 0 & 0 \\ \color{red}{\frac{1}{2}} & 1 & 0 \\ \color{blue}{\frac{1}{2}} & 0 & 1 \end{array}\right] && \left[\begin{array}{rrr} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{array}\right] \\ \xrightarrow{R_3+\color{purple}{\frac{1}{3}}\cdot R_2\to R_3}\left[\begin{array}{rrr} 2 & 5 & 3 \\ 0 & \frac{3}{2} & \frac{15}{2} \\ 0 & 0 & 2 \end{array}\right] && \left[\begin{array}{rrr} 1 & 0 & 0 \\ \color{red}{\frac{1}{2}} & 1 & 0 \\ \color{blue}{\frac{1}{2}} & \color{purple}{-\frac{1}{3}} & 1 \end{array}\right] && \left[\begin{array}{rrr} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{array}\right] \end{align*} Note that the "multiplier" $$m$$ is inserted in the $$(i, j)$$ position of $$L$$ when the operation $$R_i-m\cdot R_j\to R_i$$ is performed. Additionally, each multiplier in the $$i$$th row of $$L$$ is swapped with the multipliers in the $$j$$th row of $$L$$ when the operation $$R_i\leftrightarrow R_j$$ is performed.