[R] Error in the inverse of a diagonal matrix?

Manuel Castejon Limas manuel.castejon at dim.unirioja.es
Mon Feb 14 10:18:29 CET 2000


I´m new to R so maybe this issue has been asked before and I still could not read the complete set of past messages sent to the list.
I found a weird behabiour that I will explain with a simple example. Lets consider the following block of commands:

> x <- diag(c(1,4,10))
> x
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    4    0
[3,]    0    0   10

> invx <- x^-1
> invx
     [,1] [,2] [,3]
[1,]    1  Inf  Inf
[2,]  Inf 0.25  Inf
[3,]  Inf  Inf  0.1

I would really appreciate if the result would have been
     [,1] [,2] [,3]
[1,]  1    0    0
[2,]  0  0.25  0
[3,]  0    0  0.1

most of all because
> x %*% invx
     [,1] [,2] [,3]
[1,]  NaN  NaN  NaN
[2,]  NaN  NaN  NaN
[3,]  NaN  NaN  NaN

does not really satisfies me :-)

I´m using version 0.90.1.

Is this what it was meant to be?
Is this a known bug?
Am I doing something wrong?
Anybody knows a workaround (for a general matrix, not for a diagonal one)?

I would really appreciate your help and support.
Thanks in advance.


------------------------------------------------------------------------------------------------------------------------------------------------------
                          Manuel Castejon Limas.
                     Manuel.Castejon at dim.unirioja.es 
Departamento de Ingenieria Mecanica.   | Mechanical Engineering Department.
Area de Proyectos de Ingenieria.       | Project Management Area.
Universidad de La Rioja.               | University of La Rioja.
España.                                | Spain.
------------------------------------------------------------------------------------------------------------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000214/f7312c35/attachment.html


More information about the R-help mailing list