Description Usage Arguments Value Author(s) Source References Examples
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=TRUE)
displays the stepwise 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,...)
1 2 |
f |
function to be integrated. |
a |
starting abscissa of integral. |
b |
ending abscissa of integral. |
tol |
tolerance for termination |
trace |
should intermediate steps be traced |
... |
additional parameters for function f. |
List (Q, term) with Q = the approximate value of the integral and term = the information, whether the tolerance given was too small.
Christian W. Hoffmann christian@echoffmann.ch
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## Not run:
options(digits=7)
FexGander <- function(xx) ifelse(xx < 1,xx+1,ifelse(xx <= 3, 3 - xx, 2 ))
adaptsim(sin,0,pi,2.0e-3,TRUE)$Q - 2.0 # -1.686905e-05
adaptsim(sin,0,pi,2.0e-23)$Q - 2.0 # 0
adaptsim(FexGander,0,5)$Q - 7.5 # -7.993606e-15 instead of 0
adaptlob(FexGander,0,5,2.0e-6,TRUE) # 7.500002 instead of 7.5
adaptlob(FexGander,0,5,2.0e-6)$Q - 7.5 # 1.781274e-06 instead of 0
adaptlob(FexGander,0,5)$Q-7.5 # instead of -8.881784e-16, with warnings
# that required tolerance is too small.
adaptlob(FexGander,0,5,5.0*.Machine$double.eps)$Q-7.5 # -5.329071e-15
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.