# How to solve 3 eq. system by the inverse matrix when the matrix gets a zero on the main diagonal?

I have this system:

\begin{align*}x+2y-z=1\\x+y+z=2\\2x-y+2z=3\end{align*}

And I've done:

$\begin{array}{ccc|ccc}1&2&-1&1&0&0\\1&1&1&0&1&0\\2&-1&2&0&0&1\end{array}$

then multiply first row by $(-1)$ in order to make the (lin:2, col:1) 0. and I get:

$\begin{array}{ccc|ccc}1&2&-1&1&0&0\\0&-1&2&-1&1&0\\0&-5&0&-2&0&1\end{array}$

now I have to switch the line 2 with 3 or the col 2 with 3? (because there is a zero on the main diagonal)

If I switch, then how my variable will be switched?

-
Have you tried continuing to see what happens? – J. M. Nov 19 '11 at 18:18
None of them gives me the right result.. – Totty.js Nov 19 '11 at 18:47
Maybe because the first row should be $1,2,-1$ instead of $1,2,1$? – J. M. Nov 19 '11 at 18:50
there was a typo when I've wrote here. as you see in the second step that is right. – Totty.js Nov 19 '11 at 19:00
You should not exchange columns; but you can exchange rows. – Arturo Magidin Nov 19 '11 at 20:02

Suppose you have the equation $Ax=b$, every time you make an elemantary row operation you are actually multiplying with a matrix that represents this action. Example: you have performed one such action, multiplying the first row with $-1$ and adding it to the second row and multiplying the first row with $-2$ and adding it to the third row which is: $$\pmatrix{1 &0 &0\\-1 &1 &0\\-2&0&1}Ax=\pmatrix{1 &0 &0\\-1 &1 &0\\-2&0&1}b$$ That is the reason why it shows up on the right part of your matrix. If you keep doing this you would get $$R_n\ldots R_1Ax= R_n\ldots R_1 b$$ and $R_n\ldots R_1A$ would be an upper triangular matrix from which you can start back substitution. Hence you wouldn't be needing the column swaps at all.

The column swap can be seen by rewriting the $Ax=b$ as $APP^{-1}x = b$. This means that whenever you apply a column swap, your variables are also permuted with the inverse of the permutation matrix. The inverse of a permutation is $\ldots$ehm$\dots$ permuting back, hence easy to obtain. Suppose we apply a column swap between the column number $2$ and $3$, $$\underbrace{\left(\begin{array}{ccc}1&2&-1\\1&1&1\\2&-1&2\end{array}\right)\pmatrix{1 &0 &0\\0 &0 &1\\0 &1&0}}_{AP} \underbrace{\pmatrix{1 &0 &0\\0 &0 &1\\0 &1&0}\pmatrix{x\\y\\z}}_{P^{-1}x} = b$$ which is equal to $$\left(\begin{array}{ccc}1&-1&2\\1&1&1\\2&2&-1\end{array}\right)\pmatrix{x\\z\\y} = b$$ we can see that $b$ couldn't care less about this operation. Hence, column swap only results with more things that we have to care about (In the context of solving linear equations!). For example you can continue your work by adding $-5$ times the second row and add it to the third and you are done.

-