I chose problem C33
Let x = x1, y = x2, and z = x3 for the purposes of solving the system of equations in R.
library(matlib)
A <- matrix(c(1,1,0,1,-1,0,-1,-1,1),nrow=3,ncol=3)
b <- c(-1,-1,2)
showEqn(A,b)
## 1*x1 + 1*x2 - 1*x3 = -1
## 1*x1 - 1*x2 - 1*x3 = -1
## 0*x1 + 0*x2 + 1*x3 = 2
Is the matrix consistent? The command below tests.
all.equal( R(A), R(cbind(A,b)))
## [1] TRUE
Plotting the system of equations can be informative, and accomplished with the plotEqn command; in this case we’ll need plotEqn3d for a 3D solution.
plotEqn3d(A,b)
Solving the equation with R yields the following:
Solve(A,b,fractions=TRUE)
## x1 = 1
## x2 = 0
## x3 = 2
Reduced-row echelon form of the matrix A can be found using the package pracma and the command rref on a complete matrix representing the system of equations. The solutions to each equation form the rightmost column, and the coefficients of each variable signify the solution.
C <- cbind(A,b)
library(pracma)
rref(C)
## b
## [1,] 1 0 0 1
## [2,] 0 1 0 0
## [3,] 0 0 1 2