# reformulate the linear system as a vector equality with a matrix-vector product (Theorem SLEMM)
# The system Ax = b
A <- matrix(c(1,-1,2,1,0,-2,2,-1,-1), 3, byrow=T)
b <- matrix(c(5,-8,-6), nrow=3, ncol=1)
print(A)
## [,1] [,2] [,3]
## [1,] 1 -1 2
## [2,] 1 0 -2
## [3,] 2 -1 -1
print(b)
## [,1]
## [1,] 5
## [2,] -8
## [3,] -6
# According to Theorem SNCM, if A is non-singular than the unique solution will be given by A inverse b.
library(matlib) # This defines: inv(), Inverse(); the standard R function for matrix inverse is solve()
det(A) != 0 # det(A) != 0, so inverse exists
## [1] TRUE
A.inv <- inv(A) # Only non-singular matrices have an inverse.
print(A.inv)
## [,1] [,2] [,3]
## [1,] 2 3 -2
## [2,] 3 5 -4
## [3,] 1 1 -1
unique.solution <- A.inv%*%b # The unique solution is A inverse %*% b
print(unique.solution)
## [,1]
## [1,] -2
## [2,] -1
## [3,] 3
- reference
