ghQuad {fastGHQuad} | R Documentation |
Convenience function for Gauss-Hermite quadrature
Description
Convenience function for evaluation of Gauss-Hermite quadrature
Usage
ghQuad(f, rule, ...)
Arguments
f |
Function to integrate with respect to first (scalar) argument; this
does not include the weight function |
rule |
Gauss-Hermite quadrature rule to use, as produced by
|
... |
Additional arguments for f |
Details
This function performs classical unidimensional Gauss-Hermite quadrature with the function f using the rule provided; that is, it approximates
\int_{-\infty}^{\infty} f(x) \exp(-x^2) \, dx
by evaluating
\sum_i w_i f(x_i)
Value
Numeric (scalar) with approximation integral of f(x)*exp(-x^2) from -Inf to Inf.
Author(s)
Alexander W Blocker ablocker@gmail.com
References
Golub, G. H. and Welsch, J. H. (1969). Calculation of Gauss Quadrature Rules. Mathematics of Computation 23 (106): 221-230.
Liu, Q. and Pierce, D. A. (1994). A Note on Gauss-Hermite Quadrature. Biometrika, 81(3) 624-629.
See Also
Examples
# Get quadrature rules
rule10 <- gaussHermiteData(10)
rule100 <- gaussHermiteData(100)
# Check that rule is implemented correctly
f <- function(x) rep(1,length(x))
if (!isTRUE(all.equal(sqrt(pi), ghQuad(f, rule10), ghQuad(f, rule100)))) {
print(ghQuad(f, rule10))
print(ghQuad(f, rule100))
}
# These should be 1.772454
f <- function(x) x
if (!isTRUE(all.equal(0.0, ghQuad(f, rule10), ghQuad(f, rule100)))) {
print(ghQuad(f, rule10))
print(ghQuad(f, rule100))
}
# These should be zero