# Integral of $\int_{\mathbb{R}}e^{-\frac{x^{2}}{2}}\left(\cos\left(\pi nx\right)\right)dx$ [duplicate]

I was in need to urgently solve this integral. I already know the result in the closed form, does anybody know how to solve it? $$\int_{\mathbb{R}}e^{-\frac{x^{2}}{2}}\left(\cos\left(\pi nx\right)\right)dx=\sqrt{2\pi}e^{-\frac{n^{2}\pi^{2}}{2}},$$ If anybody already knows it is welcome, otherwise I guess I will have to look tomorrow with more calm

## marked as duplicate by T. Bongers, user147263, Silvia Ghinassi, user228113, colormegoneFeb 11 '16 at 2:46

• math.stackexchange.com/a/1644885/54122 – vnd Feb 9 '16 at 13:42
• That integrand looks like the real part of $z^n e^\frac{z^2}{2}$, which suggests converting to an integral over the complex plane which might be simpler. – John Hughes Feb 9 '16 at 13:42

Here's a funny one:

Define the function $f$ as $$f:\mathbb{R}\longrightarrow\mathbb{R},\ a\longmapsto\int_{-\infty}^{+\infty}\mathrm{e}^{-x^2/2}\cos(a x)\,\mathrm{d}x.$$ It is well-known that the improper integral defining $f$ is convergent. We can apply the differentiation theorem to differentiate this improper integral (proof left to the reader) and we obtain: $$\forall a\in\mathbb{R},\ f'(a)=-\int_{-\infty}^{+\infty}x\mathrm{e}^{-x^2/2}\sin(ax)\,\mathrm{d}x.$$ Using an integration by parts yields $$\forall a\in\mathbb{R},\ f'(a)=-a\int_{-\infty}^{+\infty}\mathrm{e}^{-x^2/2}\cos(a x)\,\mathrm{d}x=-af(a).$$ Hence $f$ is a solution of the differential equation $$f'(a)+af(a)=0,$$ the general solution of which is $$f(a)=C\mathrm{e}^{-a^2/2}.$$ Now it is well-known that: $$f(0)=\int_{-\infty}^{+\infty}\mathrm{e}^{-x^2/2}\,\mathrm{d}x=\sqrt{2\pi},$$ hence $$\forall a\in\mathbb{R},\ f(a)=\sqrt{2\pi}\mathrm{e}^{-a^2/2}.$$ In particular, $$\int_{-\infty}^{+\infty}\mathrm{e}^{-x^2/2}\cos(\pi nx)\,\mathrm{d}x=f(\pi n)=\sqrt{2\pi}\mathrm{e}^{-n^2\pi^2/2}.$$

Another chance is given by the expansion of $\cos(\pi n x)$ as a Taylor series: $$\cos(\pi n x) = \sum_{m\geq 0}\frac{(-1)^m (\pi n)^{2m} x^{2m}}{(2m)!}\tag{1}$$ together with the fact that: $$\int_{\mathbb{R}} x^{2m} e^{-x^2/2}\,dx = \int_{0}^{+\infty} x^{m-1/2} e^{-x/2}\,dx = 2^{m+1/2}\cdot\Gamma\left(m-\frac{1}{2}\right).\tag{2}$$ These identities give: $$\begin{eqnarray*} \int_{\mathbb{R}}e^{-x^2/2}\cos(\pi n x)\,dx &=& \sum_{m\geq 0}\frac{(-1)^m (\pi n)^{2m}\, 2^{m+1/2}\,\Gamma(m+1/2)}{\Gamma(2m+1)} \\ &\color{red}{=}&\sqrt{2\pi}\cdot \sum_{m\geq 0}\frac{(-1)^m (\pi n)^{2m}\, 2^{m}\,\Gamma(m+1/2)}{2^{2m}\,\Gamma(m+1/2)\,\Gamma(m+1)}\\&=&\sqrt{2\pi}\sum_{m\geq 0}\frac{(-1)^m (\pi^2 n^2/2)^m}{m!}\\&\color{blue}{=}&\sqrt{2\pi}\cdot e^{-\pi^2 n^2/2}\tag{3}\end{eqnarray*}$$ where the equality in red follows from the Legendre duplication formula and the equality in blue from the Taylor series of the exponential function.

HINT: $$\int_{\mathbb{R}}e^{-\frac{x^{2}}{2}}\left(\cos\left(\pi nx\right)\right)dx= \Re\left[ \int_{\mathbb{R}}e^{-\frac{x^{2}}{2}}e^{i\pi nx}dx\right]$$ Then observe that $$-\frac{x^2}2+i\pi nx=-\left(\frac x{\sqrt2}-\sqrt2i\pi n\right)^2+2\pi^2 n^2$$ and use the well known integral

$$\int_{\Bbb R}e^{-s^2}\,ds=\sqrt{\pi}\;\;$$

with a suitable change of variable.

• The "suitable change of variable" is not the part to dismiss lightly. The new limits are not on the real axis and one must invoke Cauchy's Integral Theorem to deform the new integration contour back onto the real axis and show that the contributions from the "end pieces" vanish. – Mark Viola Feb 9 '16 at 18:52
• I know that. That's why I wrote HINT before. – Joe Feb 9 '16 at 19:13