0

I have a function which takes an inverse of a matrix, say mat. I would like to take an inverse only if the matrix is invertible using solve function. So, I would like to make some check statement like;

if (rcond(mat) > smallnumb)
  {
  smat <- solve(mat)
  }

I do not want to make smallnumb to be too large because I want to take an inverse when I can.

My question is how small does the smallnumb have to be.

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
FairyOnIce
  • 2,526
  • 7
  • 27
  • 48
  • 3
    I would say "it depends". You can always use SVD if you find degenerate columns. I'd start with 1.0e-6 and play with it. – duffymo Dec 15 '14 at 19:56
  • 1
    An "obvious" limit is when the inverse value gets close to the machine precision limit, e.g. `.Machine$double.eps` . But you'll almost certainly get in trouble long before that when trying to invert a near-singular matrix. – Carl Witthoft Dec 15 '14 at 20:18
  • 1
    You might want to use `try` or `tryCatch` instead. – Gregor Thomas Dec 15 '14 at 21:20

0 Answers0