Equations in three unknowns

library(matlib)

Given a system of equations,

\[ \begin{alignat*}{7} 2x &&\; + \;&& y &&\; -z &&\; = \;&& 8 \\ -3x &&\; - \;&& y &&\; +2z &&\; = \;&& -11 \\ -2x &&\; + \;&& y &&\; +2z &&\; = \;&& -3 \end{alignat*} \]
And here is the augmented matrix

\[ \begin{bmatrix} 2 & 1 & -1 \\ -3 & -1 & 2 \\ -2 & 1 & 2 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 8 \\ -11\\ -3 \end{bmatrix} \] #### Create and show the equation

A <- matrix(c(2,1,-1,-3,-1,2,-2,1,2),3,3, TRUE)
b <- c(8,-11,-3)
showEqn(A,b)
##  2*x1 + 1*x2 - 1*x3  =    8 
## -3*x1 - 1*x2 + 2*x3  =  -11 
## -2*x1 + 1*x2 + 2*x3  =   -3

Find solution

Solve(A,b)
## x1      =   2 
##   x2    =   3 
##     x3  =  -1

Plot the equation

plotEqn3d(A,b)

Reduced echelon form

echelon(A, b, verbose=TRUE, fractions=TRUE)
## 
## Initial matrix:
##      [,1] [,2] [,3] [,4]
## [1,]   2    1   -1    8 
## [2,]  -3   -1    2  -11 
## [3,]  -2    1    2   -3 
## 
## row: 1 
## 
##  exchange rows 1 and 2 
##      [,1] [,2] [,3] [,4]
## [1,]  -3   -1    2  -11 
## [2,]   2    1   -1    8 
## [3,]  -2    1    2   -3 
## 
##  multiply row 1 by -1/3 
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -2/3 11/3
## [2,]    2    1   -1    8
## [3,]   -2    1    2   -3
## 
##  multiply row 1 by 2 and subtract from row 2 
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -2/3 11/3
## [2,]    0  1/3  1/3  2/3
## [3,]   -2    1    2   -3
## 
##  multiply row 1 by 2 and add to row 3 
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -2/3 11/3
## [2,]    0  1/3  1/3  2/3
## [3,]    0  5/3  2/3 13/3
## 
## row: 2 
## 
##  exchange rows 2 and 3 
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -2/3 11/3
## [2,]    0  5/3  2/3 13/3
## [3,]    0  1/3  1/3  2/3
## 
##  multiply row 2 by 3/5 
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -2/3 11/3
## [2,]    0    1  2/5 13/5
## [3,]    0  1/3  1/3  2/3
## 
##  multiply row 2 by 1/3 and subtract from row 1 
##      [,1] [,2] [,3] [,4]
## [1,]    1    0 -4/5 14/5
## [2,]    0    1  2/5 13/5
## [3,]    0  1/3  1/3  2/3
## 
##  multiply row 2 by 1/3 and subtract from row 3 
##      [,1] [,2] [,3] [,4]
## [1,]    1    0 -4/5 14/5
## [2,]    0    1  2/5 13/5
## [3,]    0    0  1/5 -1/5
## 
## row: 3 
## 
##  multiply row 3 by 5 
##      [,1] [,2] [,3] [,4]
## [1,]    1    0 -4/5 14/5
## [2,]    0    1  2/5 13/5
## [3,]    0    0    1   -1
## 
##  multiply row 3 by 4/5 and add to row 1 
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    2
## [2,]    0    1  2/5 13/5
## [3,]    0    0    1   -1
## 
##  multiply row 3 by 2/5 and subtract from row 2 
##      [,1] [,2] [,3] [,4]
## [1,]  1    0    0    2  
## [2,]  0    1    0    3  
## [3,]  0    0    1   -1