Calculating $LU$ using the Permutation Matrix Suppose we are given any matrix $A$. I know how to compute $LU$ and I know how to calculate the permutation for it. Where I am confused is for $PA$, how do we calculate $LU$? Is it the same as $A=LU$ or are the steps for $LU=PA$ different in terms of calculating $LU$ using $"PA"$?
 A: You get in trouble with computing the LU factorization if, at some step, you get a zero as the pivot element. Then you cannot divide by it, and the only way out is to resort to a permutation.
Swapping the pivot row with some row that doesn't have a zero in the pivot column produces a permutation. After that, you go on with the LU factorization (possibly with more permutations, if you stumble upon more diagonal zeroes), obtaining factors $L$ and $U$.
But, if you compute $LU$, it will -- of course -- have those rows swapped (since that is how you computed $L$ and $U$). In other words, $PA = LU$, where $P$ is a composition of all row the swaps you've made.
If you're swapping columns, $P$ goes to the right, i.e., $AP = LU$.
For best results, it is advisable to use both premutations, obtaining $P_1AP_2 = LU$. That way you can always pick the best pivot element. I'm not sure if it's always the one with the biggest absolute value, but that is certainly a good choice in terms of numerical stability. However, that discussion is a bit beyond the question being answered here.
