Elementary Matrices and LU Factorization records elimination as $A = LU$. With Partial Pivoting the rows get swapped along the way; a permutation matrix $P$ (the identity with its rows reordered) records the swaps, and the factorization becomes $$PA = LU,$$ with $L$ unit lower triangular (its multipliers all at most 1 in size) and $U$ upper triangular.
Key idea
Why it works
Worked example: Solving with the factors
- $P\mathbf{b}$: swap the first two entries, $(2, 3, 5)$.
- Forward: $y_1 = 2$; $y_2 = 3 - \left(-\frac{1}{3}\right)(2) = \frac{11}{3}$; $y_3 = 5 - \left(-\frac{2}{3}\right)(2) - 0 = \frac{19}{3}$.
- Back: $x_3 = \frac{19/3}{19/3} = 1$; $x_2 = \frac{\frac{11}{3} + \frac{1}{3}(1)}{2} = 2$; $x_1 = \frac{2 - 3(2) - 2(1)}{-6} = 1$.
- Check: $A(1, 2, 1) = (2 + 2 - 1,\ -6 + 6 + 2,\ 4 - 4 + 5) = (3, 2, 5)$.
Answer: $\mathbf{x} = (1, 2, 1)$
Worked example: A new right-hand side, no new elimination
- $P\mathbf{b} = (-8, 3, -1)$.
- Forward: $y_1 = -8$; $y_2 = 3 + \frac{1}{3}(-8) = \frac{1}{3}$; $y_3 = -1 + \frac{2}{3}(-8) = -\frac{19}{3}$.
- Back: $x_3 = -1$; $x_2 = \frac{\frac{1}{3} + \frac{1}{3}(-1)}{2} = 0$; $x_1 = \frac{-8 - 0 - 2(-1)}{-6} = 1$.
- Only about $2n^{2}$ flops: the factorization was reused.
Answer: $\mathbf{x} = (1, 0, -1)$
This split into "factor" and "solve" is how numerical libraries are organized, and it pays off whenever the same matrix meets many right-hand sides: Inverse and Shifted Power Methods solves with the same shifted matrix every step, implicit ODE methods with a fixed step solve with the same matrix every step, and the spline and boundary value systems later in the course are factored once and reused.
Reading $P$ is easy: row $i$ of $P$ has a single $1$, in column $j$, which means "entry $i$ of $P\mathbf{b}$ is entry $j$ of $\mathbf{b}$." Software usually stores $P$ as a list of row indices rather than as a matrix. In the example above, $P$ moves row 2 to the top, so $P\mathbf{b}$ starts with $b_2$.
Common mistake