# Invertible matrix
X1 <- matrix(c(3, 2, 8,
6, 3, 2,
5, 2, 4), nrow = 3, byrow = TRUE)
Y1 <- gs.gInv_MP(X1)
all.equal(Y1, solve(X1))
X1 %*% Y1
# Rectangular matrix
X2 <- X1[-1, ]
try(solve(X2))
X2 %*% gs.gInv_MP(X2)
# Non-invertible square matrix
X3 <- matrix(c(3, 0, 0,
0, 0, 0,
0, 0, 4), nrow = 3, byrow = TRUE)
try(solve(X3))
X3 %*% gs.gInv_MP(X3)
Run the code above in your browser using DataLab