\Header{integrate}{Integration of One-Dimensional Functions}
\alias{print.integrate}{integrate}
\keyword{math}{integrate}
\keyword{utilities}{integrate}
\begin{Description}\relax
Adaptive quadrature of functions of one variable over a finit or
infinite interval.\end{Description}
\begin{Usage}
\begin{verbatim}
integrate(f, lower, upper, subdivisions=100,
          rel.tol = .Machine$double.eps^0.25, abs.tol = rel.tol,
          stop.on.error = TRUE, keep.xy = FALSE, aux = NULL, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{f}] An \R{} function taking a numeric first argument and returning
a numeric vector the same length. Returning a non-finite will
generate an error.
\item[\code{lower, upper}] The limits of integration. Can be infinite.
\item[\code{subdivisions}] the maximum number of subintervals.
\item[\code{rel.tol}] relative accuracy requested.
\item[\code{abs.tol}] absolute accuracy requested.
\item[\code{stop.on.error}] logical. If true (the default) an error stops the
function.  If false some errors will give a result with a warning in
the \code{message} component.
\item[\code{keep.xy}] unused. For compatibility with S.
\item[\code{aux}] unused. For compatibility with S.
\item[\code{...}] additional arguments to be passes to \code{f}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If one or both limits are infinite, the
infinite range is mapped onto a finite interval.

For a finite interval, globally adaptive interval subdivision is used
in connection with extrapolation by the Epsilon algorithm.

\code{rel.tol} cannot be less than \code{max(50*.Machine\$double.eps,
    0.5e-28)} if \code{abs.tol <= 0}.\end{Details}
\begin{Value}
A list of class \code{"integrate"} with components
\begin{ldescription}
\item[\code{value}] the final estimate of the integral.
\item[\code{abs.error}] estimate of the modulus of the absolute error.
\item[\code{subdivisions}] the number of subintervals produced in the
subdivision process.
\item[\code{message}] \code{"OK"} or a character string giving the error message.
\item[\code{call}] the matched call.
\end{ldescription}
\end{Value}
\begin{References}\relax
Based on QUADPACK routines \code{dqags} and \code{dqagi} by
R. Piessens and E. deDoncker-Kapenga, available from Netlib.

See\bsl{}
R. Piessens, E. deDoncker-Kapenga, C. Uberhuber, D. Kahaner
\emph{Quadpack: a Subroutine Package for Automatic Integration.}
Springer Verlag, 1983.\end{References}
\begin{Examples}
\begin{ExampleCode}
integrate(dnorm, -1.96, 1.96)
integrate(dnorm, -Inf, Inf)

## a slowly-convergent integral
integrand <- function(x) {1/((x+1)*sqrt(x))}
integrate(integrand, lower = 0, upper = Inf)
integrate(integrand, lower = 0, upper = 10)
integrate(integrand, lower = 0, upper = 100000)
integrate(integrand, lower = 0, upper = 1000000, stop.on.error = FALSE)

try(integrate(function(x) 2, 0, 1))  ## no vectorizable function
integrate(function(x) rep(2, length(x)), 0, 1)  ## correct
\end{ExampleCode}
\end{Examples}

