<s>[INST] LU factorization with pivot to solve linear system I read that LUP matrix exist for any square matrix such that it is not a singular one.
But I came across a matrix that when I get the LUP and calculate Lz=Pb -> Ux = z the answer is wrong, I don't know why.
The linear equation was like that
x+y+z=2
z=2
2x+3y+z=0

the matrix is like that 
1  1  1
0  0  1
2  3  1

calculation with LUP gave out
x=-4, y=2, z=2

Though manual substitution calculations showed that the correct answer is 
x=2,y=-2,z=2

Can any one tell me why this happens is it a calculation mistake or something or it is a limitation with the LU factorization?!
[Edit]
Attempt to solve:
$$A = \begin{bmatrix} 1 & 1 & 1 \\ 0 & 0 & 1 \\ 2 & 3 & 1\\ \end{bmatrix}\rightarrow swap(r1,r3)$$
$$A = \begin{bmatrix} 2 & 3 & 1 \\ 0 & 0 & 1 \\  1 & 1 & 1\\ \end{bmatrix}\rightarrow  R_3 - \frac12 R_1$$
$$A = \begin{bmatrix} 2 & 3 & 1 \\ 0 & 0 & 1 \\  0 & - \frac12 &  \frac12\\ \end{bmatrix}\rightarrow swap(r2,r3)$$
$$A = \begin{bmatrix} 2 & 3 & 1 \\ 0 & - \frac12 &  \frac12  \\ 0 & 0 & 1  \\ \end{bmatrix} = U$$
$$L = \begin{bmatrix} 1 & 0 & 0 \\ \frac12 & 1 & 0 \\  0 & 0 & 1\\ \end{bmatrix}$$
$$b = \begin{bmatrix} 0 \\2\\2 \end{bmatrix}$$
 [/INST] As noted in the comments, we have:
$$A = P L U x = b \rightarrow LUx = P^{-1}b \rightarrow Ly = P^{-1}b, Ux = y$$
Note: you can see my $L$ and $U$ below.
$$P = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0\end{bmatrix}$$
Using this, we have:
$Ly = P^{-1}\cdot b \rightarrow \begin{bmatrix}1 & 0 & 0\\2 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix}y_1 \\ y_2\\ y_3\end{bmatrix} = \begin{bmatrix}2 \\ 0\\ 2\end{bmatrix}$
This will lead to $y = \begin{bmatrix}2 \\ -4 \\ 2\end{bmatrix}$
Next we solve:
$Ux = y \rightarrow \begin{bmatrix}1 & 1 & 1\\0 & 1 & -1 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix}x_1 \\ x_2\\ x_3\end{bmatrix} = \begin{bmatrix}2 \\ -4\\ 2\end{bmatrix}$
This will lead to $x= \begin{bmatrix}2 \\ -2 \\ 2\end{bmatrix}$.
</s>