integrate
Integral of a Real-valued Function

### Description

Approximates the integral of a real-valued function over a given interval, and estimates the absolute error in the approximation.

### Usage

    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)

### Arguments

f | a real-valued function of the form f(x,<additional arguments>), where x is the variable of integration. f must be vectorized: the output of f(x,...) should be the length of x and f(x,...)[i] should be the same as f(x[i],...).
lower, upper | the lower and upper limits of integration. Infinite limits are allowed, but they cannot be missing.
... | additional arguments for f.
subdivisions | an upper bound on the number of subdivisions of the original interval. Must larger than 1.
rel.tol | relative error tolerance. The method attempts to compute an approximation Q to the true integral I such that abs(I-Q) <= max(abs.tol,rel.tol*abs(Q). The algorithm does not proceed if abs.tol <= 0 and rel.tol < max(50*.Machine\$double.eps,.5e-28).
abs.tol | absolute error tolerance. The method attempts to compute an approximation Q to the true integral I such that abs(I-Q) <= max(abs.tol,rel.tol*abs(Q)).
stop.on.error | a logical value. If TRUE (the default), when an abnormal termination (that is, requested accuracy has not been achieved) happens, the function stops with the error message. Otherwise the inaccurate result is returned.
keep.xy | This argument is ignored. It is present for compatibility with the S+ version of this function.
aux | This argument is ignored. It is present for compatibility with the S+ version of this function.

Value
returns a list containing the following elements :

value | the approximate integral of f from lower to upper.
abs.error | an upper bound on the magnitude of the absolute error in the approximation.
subdivisions | the number of subintervals to which the quadrature rule has been applied.
message | a statement of the reason for termination.
call | a copy of the call to integrate.

References
Piessens, R., et al. 1983. Quadpack: a Subroutine Package for Automatic Integration.
Piessens, R. and deDoncker-Kapenga, E. . Based on QUADPACK routines dqags and dqagi. Available from Netlib. (They were slightly modified to deal with a vectorized integrand with extra arguments.).
Examples

    integrate(dnorm, -Inf, 1.2) # compare with pnorm(1.2)
    integrate(function(x) 1 / {(x + 1) * sqrt(x)}, lower = 0, upper = Inf)  # pi
    # A double integral via iterated integration to compute
    # the volume of an octant of the unit sphere.
    f <- function(x, y) {
        z2 <- 1 - x^2 - y^2
        ifelse(z2>0, suppressWarnings(sqrt(z2)), 0)
    }
    innerIntegral <- function(y) {
        vapply(y, function(y)integrate(f, lower=0, upper=1, y=y)$value, FUN.VALUE=0)
    }
    integrate(innerIntegral, 0, 1) # compare with 4/3*pi/8

Package stats version 6.1.5-18
Package Index