Solving Systems of Linear Equations – excersize C34
C34 Find all solutions to the linear system: #x + y ??? z = ???5 #x ??? y ??? z = ???3 #x + y ??? z = 0
To find all the soultions ginv() function Calculates the Moore-Penrose generalized inverse of a matrix X
library(matlib) #use the package## Warning: package 'matlib' was built under R version 3.4.3
A <- matrix(c(1,1,1,1,-1,1,-1,-1,-1),nrow = 3,byrow = TRUE)
B <- c(-5,-3,0)
showEqn(A, B)## 1*x1 + 1*x2 + 1*x3 = -5
## 1*x1 - 1*x2 + 1*x3 = -3
## -1*x1 - 1*x2 - 1*x3 = 0
library(MASS)## Warning: package 'MASS' was built under R version 3.4.3
x <- ginv(A) %*% B
x## [,1]
## [1,] -1.375
## [2,] 0.250
## [3,] -1.375
This gives the vaue of x = -1.375 , y = 0.250 , z = -1.375
To check if the systems of equation is consistent or not we can use the below procedure
c(R(A), R(cbind(A,B))) # show ranks## [1] 2 3
all.equal( R(A), R(cbind(A,B)) ) # show consistency## [1] "Mean relative difference: 0.5"
plotEqn3d(A,B)The ranks here are not same and consitency shows difference is 0.5 so this system of equations is not consistent.