3

I am studying R programming.

I am trying to inverting matrix. Below is what 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 not understand what 'singular' means. According to this link, it is said that if solve does not have second parameter, it inverts first parameter.

I am fully confused, so need some explanation with example would be wonderful.

Juneyoung Oh
  • 7,318
  • 16
  • 73
  • 121
  • Unfortunately for you, you are using a special case with your matrix "x". You would have more luck using a more general case (`x <- matrix(rnorm(16),4,4)`). –  May 23 '15 at 09:51
  • 2
    Possible duplicate of [R solve:system is exactly singular](http://stackoverflow.com/questions/6572119/r-solvesystem-is-exactly-singular) – zx8754 Oct 08 '15 at 09:33

1 Answers1

8

If you compute the determinant of the matrix, it is 0:

det(x)
[1] 0

By definition, your matrix is not invertible. But before trying to invert a squared matrix, the first instinct should be to study analytically if the matrix can be invertible.

The singular error you get just reflects the matrix is not invertible.

Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87