

   AAddaappttiivvee qquuaaddrraattuurree iinn ffrroomm 11 ttoo 2200 ddiimmeennssiioonnss..

        adapt(ndim, lower, upper, minpts, maxpts, functn, eps,...)
        integrate(functn, lower,upper,minpts=100,maxpts=500,eps=0.01,...)

   AArrgguummeennttss::

       ndim: the number of dimensions of the function/integral

      lower: vector of at least length ndim of the lower bounds
             on the integral

      upper: vector of at least length ndim of the upper bounds
             on the integral

     minpts: the minimum number of function evaluations

     maxpts: the maximum number of function evaluations

     functn: the name of an S function.  `functn' should take a
             single vector argument and possibly some parame-
             ters and return the function value at that point.
             `functn' must return a single numeric value.

        eps: The desired accuracy.

        ...: Other parameters to be passed to `functn'

   DDeessccrriippttiioonn::

        `integrate()' integrates a function of 1 variable over
        a specified interval, `adapt()' allows 1 to 20 vari-
        ables and integrates over a rectangular box

   VVaalluuee::

        structure containing finest, relerr, minpts and ifail.

     finest: the estimated integral

     relerr: the estimated relative error

     minpts: the actual number of function evaluations

      ifail: an error indicator.  If ifail is not equal to 0,
             the function warns the user of the error condi-
             tion.

   NNoottee::

        This is modified from Mike Meyer's S code. The func-
        tions just call A.C. Genz's fortran ADAPT subroutine to
        do all of the calculations.  A work array is allocated
        with the C/Fortran code.  The function may complain
        that maxpts is not large enough, and will automatically
        make increase maxpts.

        The Fortran function has been modified to use double
        precision, for compatibility with R. It only works in
        two or more dimensions; for one-dimensional integrals
        we integrate over a strip of unit width.

   EExxaammpplleess::

        > fred <- function(z) { 0.3989423^length(z) * exp(-0.5 * sum(z * z))}
        > adapt(3,c(-2,-2,-2),c(2,2,2),100,500,fred,.01)
        Allocating a work space of size 54
        $finest:
        [1] 0.869198

        $relerr:
        [1] 2.579765e-05

        $minpts:
        [1] 345

        $ifail:
        [1] 0

        In this example of a three dimensional spherical normal distribution,
        integrate() took 345 function evaluations to find the integral.

        integrate(dnorm,-1.96,1.96)
         normloc<-function(x,mu) dnorm(x-mu)
         integrate(normloc,-1.96,1.96,mu=0)
         integrate(normloc,-2.96,0.96,mu=-1)

