adaptlob {cwhmisc} | R Documentation |
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,...)
adaptsim(f,a,b,tol=.Machine$double.eps,trace=FALSE,...) adaptlob(f,a,b,tol=.Machine$double.eps,trace=FALSE,...)
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. |
The approximate value of the integral.
Christian W. Hoffmann, c-w.hoffmann@sunrise.ch,
http://www.wsl.ch/personal_homepages/hoffmann/index_EN
Walter Gautschi, 08/03/98. Reference: Gander, Computermathematik, Birkhaeuser, 1992.
Gander, W., Gautschi, W., 2000. Adaptive Quadrature - Revisited. ETH Zurich, DI IWR technical report 306. BIT 40, 1, 84–101.
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