TITLE(integrate @@
Adaptive quadrature in from 1 to 20 dimensions.
)
USAGE(
adapt(ndim, lower, upper, minpts, maxpts, functn, eps,...)
integrate(functn, lower,upper,minpts=100,maxpts=500,eps=0.01,...)
)
ALIAS(adapt)
ALIAS(integrate)
ARGUMENTS(
ARG(ndim @@
the number of dimensions of the function/integral
)
ARG(lower @@
vector of at least length ndim of the lower bounds on the integral
)
ARG(upper @@
vector of at least length ndim of the upper bounds on the integral
)
ARG(minpts @@
the minimum number of function evaluations
)
ARG(maxpts @@
the maximum number of function evaluations
)
ARG(functn @@
the name of an S function.  LANG(functn) should take a single vector
argument and possibly some parameters and return the function value at
that point. LANG(functn) must return a single numeric value.
)
ARG(eps @@
The desired accuracy.
)
ARG(... @@
Other parameters to be passed to LANG(functn)
))
VALUES(
structure containing finest, relerr, minpts and ifail.
@@
ARG(finest @@
the estimated integral
)
ARG(relerr @@
the estimated relative error
)
ARG(minpts @@
the actual number of function evaluations
)
ARG(ifail @@
an error indicator.  If ifail is not equal to 0, the function
warns the user of the error condition.
))
DESCRIPTION( LANG(integrate()) integrates a function of 1 variable over a 
specified interval,
LANG(adapt()) allows 1 to 20 variables and integrates over a rectangular
box
)

NOTE( This is modified from Mike Meyer's S code. The functions 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.
)

EXAMPLES(
> 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
BLANK
$relerr:
[1] 2.579765e-05
BLANK
$minpts:
[1] 345
BLANK
$ifail:
[1] 0
BLANK
PARA
In this example of a three dimensional spherical normal distribution,
integrate() took 345 function evaluations to find the integral.
BLANK
 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)

)
COMMENT(KEYWORD())
COMMENT(Converted by sd2rd version 0.1-3.)
