\[ x + y − z = −1 \\ x − y − z = −1\\ z =2 \]
M <- matrix(c(1, 1, -1, 1, -1, -1, 0, 0, 1), ncol = 3, byrow = TRUE)
v <- matrix(c(-1, -1, 2),ncol = 1)
M
## [,1] [,2] [,3]
## [1,] 1 1 -1
## [2,] 1 -1 -1
## [3,] 0 0 1
v
## [,1]
## [1,] -1
## [2,] -1
## [3,] 2
sol <- solve(M,v)
sol
## [,1]
## [1,] 1
## [2,] 0
## [3,] 2
M %*% sol
## [,1]
## [1,] -1
## [2,] -1
## [3,] 2
t(M) * M
## [,1] [,2] [,3]
## [1,] 1 1 0
## [2,] 1 1 0
## [3,] 0 0 1
# That looks good
solve(M) %*% v # This way is a bit more by hand since we actually multiply the invers matrix by v.
## [,1]
## [1,] 1
## [2,] 0
## [3,] 2