[R] matrix inverse in C

FMGCFMGC FMGCFMGC at terra.es
Sun Feb 29 13:38:54 CET 2004


Hello!

For calculating the Choleski factor, you should look at:

LINPACK: dpofa, dchdc, (dppfa, although i think this one is not 
included with R)

The R code of function chol() is a good starting point. It is located at
%RHOME%/library/base/R/base (line 4115 on the windows version of R 
1.8.1 patched)

LAPACK: dpotrf, dpotf2, dpptrf

For matrix inversion you have:

LAPACK: dgesv, dposv, dsysv for general, positive definite or symmetric 
matrices, respectively.

For instructions on how to use this subroutines, look at the comments 
in the code, available at:

LINPACK: http://www.netlib.org/linpack/
LAPACK:  http://www.netlib.org/lapack/

Good luck!
Francisco

----- Mensaje Original -----
De  "Liaw, Andy" <andy_liaw at merck.com> 
Fecha  Sat, 28 Feb 2004 08:40:41 -0500 
A  "'Kosuke Imai'" <kimai at princeton.edu>, r-help at stat.math.ethz.ch 
Asunto  RE: [R] matrix inverse in C 


In section 5.7 of the `Writing R Extensions' manual, it mentions the
interface to numerical linear algebra routines (LINPACK, etc.).  You 
will
need to figure out which are the ones you need and how to call them.  As
these are expressed as Fortran routines, you can call them from C using 
the
F77_CALL() macro mentioned in that manual.

I believe many would say that routines in Numerical Recipes are not 
really
`industrial strength'...

HTH,
Andy

> From: Kosuke Imai
> 
> Hi,
>   I'm writing an R package using the C code i've written. I'm 
> wondering if
> anyone knows an easy way to calculate an inverse and cholesky 
> factor of a
> matrix using the Fortran/C library of R: and how to call them 
> from C. My
> code is based on the Numerical Reciepe code, and I'm trying to use
> something that is already in R.
> Thanks for your help in advance,
> Kosuke
> 
> ---------------------------------------------------------
> Kosuke Imai               Office: Corwin Hall 041
> Assistant Professor       Phone: 609-258-6601 (Direct)
> Department of Politics    Fax: 609-258-1110 (Department)
> Princeton University      Email: kimai at Princeton.Edu
> Princeton, NJ 08544-1012  http://www.princeton.edu/~kimai




More information about the R-help mailing list