#C32 (Chris Black) Find all solutions to the linear system:
# x + 2y = 8
# x - y = 2
# x + y = 4
#Using matlib
library(matlib)
#Setting matrix for linear equation
A <- matrix(c(1,1,1, 2, -1, 1), 3, 2)
b <- c(8,2,4)
showEqn(A, b)
## 1*x1 + 2*x2 = 8
## 1*x1 - 1*x2 = 2
## 1*x1 + 1*x2 = 4
#We know that mean relative difference is 0.5. Equations are inconsistent when r(A) < r(A|b).
all.equal( R(A), R(cbind(A,b)) )
## [1] "Mean relative difference: 0.5"
#We can see this in the result of reducing A|b to echelon form.
echelon(A, b)
## [,1] [,2] [,3]
## [1,] 1 0 4
## [2,] 0 1 2
## [3,] 0 0 -2
#Apparently, there are multiple solutions and solutions do not intersect all 3 equations simultaneously.
Solve(A, b, fractions=TRUE)
## x1 = 4
## x2 = 2
## 0 = -2
#From plot we know that x + 2y = 8 intersects x + y = 4 and x + 2y = 8 intersects x - y = 2 when x + y = 4 intersects x - y = 2.
#There is no solution that intersects 3 equations simultaneously.
#We do not have consistent solution.
plotEqn(A,b)
## x1 + 2*x2 = 8
## x1 - 1*x2 = 2
## x1 + x2 = 4
