Sometimes when finding the upper triangular of a matrix, I may just happen to switch rows to make the whole process shorter. Say for this matrix: $$ A=\begin{bmatrix} 1 & -1 & -1\\ 3 & -3 & 2\\ 2 & 1 & 1 \end{bmatrix} $$
The determinant of it is $\left | A \right | = -5$.
Then to find the upper triangular matrix of A, I thought maybe switching row2 and row 3 would make the process simpler. So I did this: $$ \begin{bmatrix} 1 & 0 & 0\\ 0 & 0 & 1\\ 0 & 1 & 0 \end{bmatrix}\cdot A=\begin{bmatrix} 1 & -1 & -1\\ 2 & -1 & 1\\ 3 & -3 & 2 \end{bmatrix} $$ And I let this be B this way: $B=\begin{bmatrix} 1 & -1 & -1\\ 2 & -1 & 1\\ 3 & -3 & 2 \end{bmatrix}$.
I figure out the elementary rows: $$ E_{21} = \begin{bmatrix} 1 & 0 & 0\\ -2& 1 & 0\\ 0 & 0 & 1 \end{bmatrix}, E_{31} = \begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ -3 & 0 & 1 \end{bmatrix} $$
Multiply the elementary row matrices to the matrix $B$: $$ E_{31}\cdot E_{21}\cdot B= \begin{bmatrix} 1 & -1 & -1\\ 0 & 1 & 3\\ 0 & 0 & 5 \end{bmatrix} $$
Now I got the upper triangle of matrix B, which is also the upper triangle of matrix $A$. Then I do a check on its determinant: $1\cdot 1\cdot 5=5$.
To my surprise, I get $5$ instead of $-5$! I realise that this is because $\left | B \right | = 5$. But since I had a row exchange to get the upper triangle, how can I make sure that its determinant is also the same as its original matrix $A$, which should be $-5$? I thought this is quite important because sometimes I use this to find the determinant value of higher dimension matrices.
Thanks for any help.