Learn R Programming

pracma (version 1.4.5)

quadinf: Infinite Integrals

Description

Adaptive quadrature of functions over an infinite interval.

Usage

quadinf(f, xa, xb, tol = .Machine$double.eps^0.5,
            method = NULL, ...)

Arguments

f
univariate function; needs to be vectorized.
xa
lower limit of integration; can be infinite
xb
upper limit of integration; can be infinite
tol
accuracy requested.
method
select the integration method.
...
additional arguments to be passed to f.

Value

  • A single numeric value, the computed integral.

Details

quadinf is simply a wrapper for integrate. When one of the integration limits become infinite, the transformed function (1/x^2)*f(1/x) is used. This works fine if the new function does not have a too bad behavior at the limit(s).

The function needs to be vectorized as long as this is required by integrate.

Choices for adaptive integration methods are ``Kronrod", ``Richardson", ``Clenshaw", ``Simpson", or ``Romberg". If the method is NULL the standard integrate() function from R base will be used.

See Also

integrate

Examples

Run this code
##  We will look at the error function exp(-x^2)
f <- function(x) exp(-x^2)
quadinf(f, -Inf, 0)  #=> 0.886226925756445 with abs. error 3e-10 (sqrt(pi)/2)
quadinf(f, 0, Inf)   # same
quadinf(f, -Inf, -1, tol = 1e-12) - integrate(f, -Inf, -1)$value
quadinf(f, -Inf,  1, tol = 1e-12) - integrate(f, -Inf,  1)$value
quadinf(f, -1,  Inf, tol = 1e-12) - integrate(f, -1,  Inf)$value
quadinf(f,  1,  Inf, tol = 1e-12) - integrate(f, -Inf, -1)$value

Run the code above in your browser using DataLab