[R] laplace transform

Martin Maechler maechler at stat.math.ethz.ch
Sat Sep 6 19:27:59 CEST 2003

>>>>> "Andrew" == Andrew C Ward <s195404 at student.uq.edu.au>
>>>>>     on Sat,  6 Sep 2003 11:32:41 +0000 writes:

    Andrew> Dear Ravi, R calls many functions that are written
    Andrew> in FORTRAN. As a start on how to do this, perhaps
    Andrew> look at the cluster package.

But that doesn't help Ravi.
He needs to learn how to call R functions from compiled code,
since one wants the laplace transform of an R function.

1) you can do this only from C, not from Fortran
2) This is not a big problem, since it will be the C code that
   both calls into Fortran and into R.

In some sense, this problem is very much similar ``in spirit''
to solving differential equations: 
You have functions as input and functions as output.
And you are lucky: The "odesolve" CRAN package has the same
basic setup as you: It uses a Fortran algorithm to solve
differential equations specified by R functions.

So download odesolve (source, not "install package"), study its
code and learn :-)  You definitely should also (first) learn
from reading in the "Writing R Extensions" manual, particularly
the chapter "System and foreign language interfaces".

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

    Andrew> Quoting Ravi Varadhan <rvaradha at jhsph.edu>:

    >> Hi:
    >> I have written a Fortran program based on the
    >> Gaver-Stehfest algorithm, which uses only real numbers
    >> (as opposed to the more powerful methods using complex
    >> numbers). However, this can't be used in R since the
    >> function specifying the inverse of the Laplace transform
    >> must also be written in Fortran.  I would be interested
    >> in learning how to define the function in R and then
    >> calling the Fortran subroutines to do the inverse
    >> computations. Can anyone tell me how to do this?
    >> thanks, Ravi.
    >> ----- Original Message ----- From: "Andrew C. Ward"
    >> <s195404 at student.uq.edu.au> Date: Friday, September 5,
    >> 2003 1:03 am Subject: Re: [R] laplace transform
    >> > Dear Luca,
    >> > 
    >> > I don't think that R has a built-in function for doing
    >> > Laplace or inverse Laplace transforms. I remember
    >> having to > use an IMSL routine (INLP, I think) to do
    >> this many years > ago. When I looked at the article that
    >> the algorithm was > based on, I found that as an example
    >> the author showed how > well the method worked when
    >> inverting 1/s! Presumably,
    >> > things have improved since then.
    >> > 
    >> > A Google search of (numerical "inverse laplace
    >> transform") > yields a number of references that should
    >> get you started.  > If you write some R code to do this,
    >> think about submitting > it to CRAN. Even though a lot of
    >> R/S code is devoted to > statistical methods, there's no
    >> reason at all why all kinds > of other things can't be
    >> written.
    >> > 
    >> > 
    >> > Regards,
    >> > 
    >> > Andrew C. Ward
    >> > 
    >> > CAPE Centre > Department of Chemical Engineering > The
    >> University of Queensland > Brisbane Qld 4072 Australia >
    >> andreww at cheque.uq.edu.au
    >> > 
    >> > 
    >> > Quoting Luca Laghi <llaghi at foodsci.unibo.it>:
    >> > 
    >> > > Dear users, > > is anybody of you aware of a R
    >> command to perform laplace > > transform or > > even its
    >> inversion?  > > Thank you very much.  > > Luca
    >> > >

More information about the R-help mailing list