1
$\begingroup$

I'm using Gauss-Hermite quadrature to integrate

$$ \int_{-\infty}^{\infty} \! e^{-x^2} \cos x\,\mathrm{d}x $$

The exact solution is evidently $\sqrt{\pi\,\text{exp}(1/4)}$, but to be honest I don't even understand what this value is supposed to represent. How is $\cos x$ from ($-\infty,\infty$) a small, finite number? I've written code to apply the weights and abscissas for $2\text{ to } 16$ points, but the numbers I've gotten do not approach the true value and do not even converge on anything as I increase the number of points.

Would appreciate any guidance.

  • 0
    Please use TeX formatting next time.2012-04-23

3 Answers 3

1

Your integral is supposed to have the exact value $\dfrac{\sqrt \pi}{\sqrt[4]{e}}$; I did my own Gauss-Hermite tests and they do just fine. Here's my Mathematica run:

(* Golub-Welsch algorithm *)
golubWelsch[d_?VectorQ, e_?VectorQ] := 
 Transpose[
  MapAt[(First[e] Map[First, #]^2) &, 
   Eigensystem[
    SparseArray[{Band[{1, 1}] -> d, Band[{1, 2}] -> Sqrt[Rest[e]], 
      Band[{2, 1}] -> Sqrt[Rest[e]]}, {Length[d], Length[d]}]], {2}]]

(* generate nodes and weights for Gauss-Hermite quadrature *)
ghq[n_Integer, prec_: MachinePrecision] := 
 Transpose[
  Sort[golubWelsch[ConstantArray[0, n], 
    N[Prepend[Range[n - 1]/2, Sqrt[Pi]], prec]]]]

(* number of good digits in successive approximations *)
Table[-Log[10, 
   Abs[Total[MapThread[#2 Cos[#1] &, ghq[n, 20]]] - Sqrt[Pi/Sqrt[E]]]/
    Sqrt[Pi/Sqrt[E]]], {n, 2, 10}]

{1.622937662555359724, 2.92393460116332523, 4.371438080373419,
 5.92810888858934, 7.571888699825, 9.2881713033, 11.06655943,
 12.8992701, 14.78026}

This says for instance that the ten-point quadrature rule gives fourteen or so accurate digits for your integral; that isn't bad in my book. Check your implementation and report back.

0

The factor $e^{-x^2/2}$ "zeroes out" the $\cos(x)$ term.

0

Another way to look at why this is by recalling that $A \cos x$ has amplitude $|A|$. Here the amplitude is not constant but a decreasing function of $x$: $A = e^{-x^2}$. The graph of $y=e^{-x^2} \cos x$ is bound between $y = \pm e^{-x^2}$.