R inverting matrix with error return error

I am learning R programming.

I am trying to invert a matrix. Below I have tried.

x <- matrix(1:16, 4, 4)
x
#      [,1] [,2] [,3] [,4]
# [1,]    1    5    9   13
# [2,]    2    6   10   14
# [3,]    3    7   11   15
# [4,]    4    8   12   16

solve(x)
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

solve(x) %*% x
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

x %*% solve(x)
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

      

I can't figure out what "only" means. According to this it says that if it solve

doesn't have a second parameter, it will invert the first parameter.

I am totally confused so need some explanation with an example would be great.

+3


source to share


1 answer


If you are calculating determinant

matrices it is 0

:

det(x)
[1] 0

      



By definition, your matrix is ​​not reversible. But before attempting to invert a square matrix, the first instinct should be to investigate analytically if the matrix can be invertible.

The only error you get is simply reflecting the matrix, not reversible.

+8


source







All Articles