I'm trying to learn Gauss Hermite Integration and was manually try to calculate the value of integral of $\frac{1}{1+x^2}$ from $-\infty$ to $+\infty$ The exact answer is simply $\pi$ ($\approx$ 3.14). But I keep getting answers that are a bit far off even with 5 nodes. Below are my calculations, could somebody please point anything obviously wrong or may be the method is more accurate for certain kind of functions.

Edit: even with 100 nodes, I only got as close as 2.93.

I got weights from - http://www.efunda.com/math/num_integration/findgausshermite.cfm

Gauss Hermite Quad of 1/(1+x^2)


If you look at this description of Hermite-Gauss quadrature on MathWorld, its error term is $$ \frac{n!\sqrt\pi}{2^n(2n)!}f^{(2n)}(\xi), $$ where $\xi$ is some point in the region of integration.

When you integrate your function $$ \frac{e^{x^2}}{1+x^2}, \qquad I = \int \frac{e^{x^2}}{1+x^2}W(x)\,dx, \quad W(x) = e^{-x^2},$$ its $2n$-th derivate is extremely large, due to the $e^{x^2}$ term that you included to cancel out the weighting function $W(x)=e^{-x^2}$. Another way to look at this is that with these interpolating polynomials and this weight function, the function $(1+x^2)^{-1}$ is not easy to approximate: it doesn't decay nearly fast enough as $x\to\pm\infty$ for the weighting function to make sense. There is a mismatch between how quickly the weighting function goes to zero and your function.

Compare this, for example, with integrating $$ \int\frac{e^{-x^2}}{1+x^2}\,dx = \int \frac{1}{1+x^2}\,W(x)\,dx, $$ where the integrand $(1+x^2)^{-1}$ doesn't have such quickly growing derivatives, and for $n=5$ the approximate integral is $1.36343\ldots$, which is off by only $1.5\%$.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.