Short version of my question
Can I only apply the Gauss-Hermite routine with an infinite interval or can I transform the interval?
Long version (reason I'm asking)
I am interested in solving integral equations numerically and one part of this, if I understood it correctly, is the usage of numerical integration routines. So I ventured into this field and implemented the midpoint, the Simpson, and the Gauss-Legendre routine successfully.
Here is my implementation of the Gauss-Legendre routine in R (depending on the package statmod
):
gauss_legendre <- function(f, upper, lower, nr_int, ...) { #1. Compute the nodes; those are the roots of the legendre-polynom leg_poly <- gauss.quad(nr_int) x <- leg_poly$nodes #2. Compute the weights as follows: 2/((1-x^2)Ableitung(P(x))^2) w <- leg_poly$weights #3. Compute the integral x_transformed <- ((x+1)*(upper - lower)/2 + lower) (upper - lower)/2*sum(w * mapply(f, x_transformed, ...)) }
So basically, the first two parts give me the numbers tabulated here and the third part just computes:
$\int_a^b f(x)dx = \frac{b-a}{2}\sum\limits_{i=1}^n \omega_i f\left( \frac{b-a}{2}x_i + \frac{a + b}{2} \right)$
Let's check that it works (note that integrate
is just the built-in function in R):
gauss_legendre(function(x) {x^3 + log(x) + sqrt(x)}, 10, 2, 10) [1] 2528.836 > integrate(function(x) {x^3 + log(x) + sqrt(x)}, 2, 10) 2528.836 with absolute error < 2.8e-11
As you can see, this works with an interval ranging from 2 to 10 by transforming the $x$ values. Given that the interval is well defined, I don't see any problem using that for any interval.
Next, I implemented the Gauss-Hermite routine:
gauss_hermite <- function(f, upper, lower, nr_int, ...) { #1. Compute the nodes; those are the roots of the Hermite-polynom her_poly <- gauss.quad(nr_int, "hermite") x <- her_poly$nodes #2. Compute the weights according to the function; attention: this already includes the term exp(x^2) w <- her_poly$weights * exp(x^2) #3. Compute the integral sum(w * mapply(f, x)) }
This works for instance when computing the integral of the density function of the standard normal distribution:
gauss_hermite(dnorm, -Inf, Inf, 100) 1
However, I don't get any useful results when the interval doesn't go from $[-\infty; \infty]$. On the other side, in none of the material I read was it mentioned that the Gauss-Hermite approach is limited to that case (I read that it's useful in connection with Normal random variables though). So my question (sorry for the long prolog): can I only apply the Gauss-Hermite routine with an infinite interval or can I transform the interval?
As you probably guessed from the question, I'm not a mathematician, so any help with this would be great.