ghQuad: Convenience function for Gauss-Hermite quadrature

View source: R/integrate.R

ghQuadR 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 exp(-x^2)

rule

Gauss-Hermite quadrature rule to use, as produced by gaussHermiteData

...

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

integral( f(x) exp(-x^2), -Inf, Inf)

by evaluating

sum( w * f(x) )

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

gaussHermiteData, ghQuad

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

awblocker/fastGHQuad documentation built on May 6, 2022, 5:49 a.m.