quadl.RdAdaptive quadrature of functions of one variable over a finite interval.
quadl(f, xa, xb, tol = .Machine$double.eps^0.5, trace = FALSE, ...)Realizes adaptive Lobatto quadrature in R through recursive calls.
The function f needs to be vectorized though this could be changed
easily.
A single numeric value, the computed integral.
Gander, W. and W. Gautschi (2000). “Adaptive Quadrature — Revisited”. BIT, Vol. 40, 2000, pp. 84-101.
Compared to Gaussian quadrature, Lobatto integration include the end points of the integration interval. It is accurate for polynomials up to degree 2n-3, where n is the number of integration points.
# options(digits=15)
f <- function(x) x * cos(0.1*exp(x)) * sin(0.1*pi*exp(x))
quadl(f, 0, 4) # 1.2821290743501
#> [1] 1.282129
integrate(f, 0, 4)
#> 1.282129 with absolute error < 4.1e-06
# 1.28212907435010 with absolute error < 4.1e-06
if (FALSE) { # \dontrun{
xx <- seq(0, 4, length.out = 200)
yy <- f(xx)
plot(xx, yy, type = 'l')
grid()} # }