Learn R Programming

cwhmisc (version 2.1)

adaptlob: Numerically evaluate integral using adaptive rule.

Description

adaptsim and adaptlob approximate the integral of the function f using adaptive Simpson and Lobatto rule. Both methods can deal with discontinuous functions. adaptlob is more efficient than adaptsim when the accuracy requirement is high. For lower tolerances, adaptsim is generally (but not always) more efficient than adaptlob, but less reliable.

Both routines show excellent response to changes in the tolerance. The function f must return a vector of output values if given a vector of input values.

adapt...(f,a,b) approximates the integral of f(x) from a to b to machine precision.

adapt...(f,a,b,tol) integrates to a relative error of tol.

adapt...(f,a,b,tol,trace) displays the left end point of the current interval, the interval length, and the partial integral.

adapt...(f,a,b,tol,trace,P1,P2,...) allows coefficients P1, ... to be passed directly to the function f: g <- f(x,P1,P2,...)

Usage

adaptsim(f,a,b,tol=.Machine$double.eps,trace=FALSE,...)
adaptlob(f,a,b,tol=.Machine$double.eps,trace=FALSE,...)

Arguments

f
function to be integrated.
a
starting abscissa of integral.
b
ending abscissa of integral.
tol
error tolerance > 0.
trace
if TRUE then trace will be displayed.
...
additional coefficients for function f if necessary.

Value

  • The approximate value of the integral.

source

Walter Gautschi, 08/03/98. Reference: Gander, Computermathematik, Birkhaeuser, 1992.

References

Gander, W., Gautschi, W., 2000. Adaptive Quadrature - Revisited. ETH Zurich, DI IWR technical report 306. BIT 40, 1, 84--101.

Examples

Run this code
FexGander <- function(xx) ifelse(xx < 1,xx+1,ifelse(xx <= 3, 3 - xx, 2 ))
adaptsim(FexGander,0,5,2.0e-6,TRUE) # 7.499949 instead of 7.5
adaptlob(FexGander,0,5,2.0e-6,TRUE) # 7.500002 instead of 7.5
adaptsim(FexGander,0,5)-7.5 # -7.993606e-15 instead of 0

Run the code above in your browser using DataLab