# integrate

0th

Percentile

##### Integration of One-Dimensional Functions

Adaptive quadrature of functions of one variable over a finite or infinite interval.

Keywords
utilities, math
##### Usage
integrate(f, lower, upper, ..., subdivisions = 100L,

##### Value

• A list of class "integrate" with components
• valuethe final estimate of the integral.
• abs.errorestimate of the modulus of the absolute error.
• subdivisionsthe number of subintervals produced in the subdivision process.
• message"OK" or a character string giving the error message.
• callthe matched call.

##### Note

Like all numerical integration routines, these evaluate the function on a finite set of points. If the function is approximately constant (in particular, zero) over nearly all its range it is possible that the result and error estimate may be seriously wrong.

When integrating over infinite intervals do so explicitly, rather than just using a large number as the endpoint. This increases the chance of a correct answer -- any function whose integral over an infinite interval is finite must be near zero for most of that interval.

For values at a finite set of points to be a fair reflection of the behaviour of the function elsewhere, the function needs to be well-behaved, for example differentiable except perhaps for a small number of jumps or integrable singularities.

f must accept a vector of inputs and produce a vector of function evaluations at those points. The Vectorize function may be helpful to convert f to this form.

##### source

Based on QUADPACK routines dqags and dqagi by R. Piessens and E. deDoncker--Kapenga, available from Netlib.

##### References

R. Piessens, E. deDoncker--Kapenga, C. Uberhuber, D. Kahaner (1983) Quadpack: a Subroutine Package for Automatic Integration; Springer Verlag.

##### Aliases
• integrate
• print.integrate
##### Examples
library(stats) 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) ## don't do this if you really want the integral from 0 to Inf integrate(integrand, lower = 0, upper = 10) integrate(integrand, lower = 0, upper = 100000) integrate(integrand, lower = 0, upper = 1000000, stop.on.error = FALSE) ## some functions do not handle vector input properly f <- function(x) 2.0 try(integrate(f, 0, 1)) integrate(Vectorize(f), 0, 1) ## correct integrate(function(x) rep(2.0, length(x)), 0, 1) ## correct ## integrate can fail if misused integrate(dnorm, 0, 2) integrate(dnorm, 0, 20) integrate(dnorm, 0, 200) integrate(dnorm, 0, 2000) integrate(dnorm, 0, 20000) ## fails on many systems integrate(dnorm, 0, Inf) ## works
Documentation reproduced from package stats, version 3.3, License: Part of R 3.3

### Community examples

Looks like there are no examples yet.