[R] Matrix inverse

Alberto Murta amurta at ipimar.pt
Fri Apr 28 21:18:02 CEST 2000


Patrik Waldmann wrote:
> 
> I haven't found a function that directly calculates the matrix inverse, does it exist? Otherwise what would be the fastest way to do it?
> 

You can use solve(), or if your matrix is not square, you can calculate
the generalised inverse using the singular value decomposition function
svd().
If you have a matrix X, svd(X) will return 1 vector d and 2 matrices u
and v.
The inverse of X is then the matrix calculated as v%*%diag(1/d)%*%t(u).
If any element of vector d is 0, then replace the corresponding element
in diag(1/d) by 0.


Alberto

 
__________________ Alberto G. Murta ______________________
     IPIMAR - Institute of Fisheries and Sea Research  
      Avenida de Brasilia; 1449-006 Lisboa; Portugal
Tel:351 213027062; Fax:351 213015948; http://www.ipimar.pt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list