# Calculating the integral $\int_{0}^{\infty} \frac{\cos x}{1+x^2}\mathrm{d}x$ without using complex analysis

Suppose that we do not know anything about the complex analysis (numbers). In this case, how to calculate the following integral in closed form? $$\int_0^\infty\frac{\cos\;x}{1+x^2}\mathrm{d}x$$

-
Study complex analysis, and come back to the problem with fresh ideas. –  Yuval Filmus Nov 8 '10 at 7:52
@Yuval Filmus, that is a bad comment. –  anon Nov 8 '10 at 10:21
Complex analysis methods: math.stackexchange.com/questions/100616/… –  Aryabhata Jan 20 '12 at 2:52

This can be done by the useful technique of differentiating under the integral sign.

In fact, this is exercise 10.23 in the second edition of "Mathematical Analysis" by Tom Apostol.

Here is the brief sketch (as laid out in the exercise itself).

Let $$F(y) = \int\limits_{0}^{\infty} \frac{\sin xy}{x(1+x^2)} \ dx \ \ \text{for} \quad\quad y > 0$$

Show that

$\displaystyle F''(y) - F(y) + \pi/2 = 0$ and hence deduce that $\displaystyle F(y) = \frac{\pi(1-e^{-y})}{2}$.

Use this to deduce that for $y > 0$ and $a > 0$

$$\displaystyle \int_{0}^{\infty} \frac{\sin xy}{x(x^2 + a^2)} \ dx = \frac{\pi(1-e^{-ay})}{2a^2}$$

and

$$\int_{0}^{\infty} \frac{\cos xy}{x^2 + a^2} dx = \frac{\pi e^{-ay}}{2a}$$

-
+1: as usual, Moron does a great job! –  user1709 Nov 8 '10 at 8:20
Very nice. –  user02138 Nov 8 '10 at 8:22
Reminds me of how people were so amazed at Feynman because he could differentiate under the integral. ;) –  Ｊ. Ｍ. Nov 8 '10 at 10:21
@JM: yes, i remembered reading that story about Feynman ;-) when i saw Moron's answer. –  user1709 Nov 8 '10 at 17:01
@AmadeusDrZaius: Differentiate $F(y)$ (differentiate with respect to $y$ inside the integral). –  Aryabhata May 7 at 0:21

Since $$\frac{x}{1+x^2}=\int_{0}^{\infty}e^{-y}\sin (xy)dy,$$ we have that $$I=\int_{0}^{\infty}\frac{\cos bx}{1+x^2}dx=\int_{0}^{\infty}\frac{\cos bx}{x}dx\int_{0}^{\infty}e^{-y}\sin (xy)dy.$$ Changing the order of integration (which can be justified by the standard method) yields $$I=\int_{0}^{\infty}e^{-y}dy\int_{0}^{\infty}\frac{\sin xy}{x} \cos bx dx.$$ The calculation of the integral (a.k.a. the discontinuous Dirichlet factor) $$\int_{0}^{\infty}\frac{\sin xy}{x} \cos bx dx=\begin{cases}0, & 0 < y < b \\ \ \\ \pi/2, & 0 < b < y, \end{cases}$$ can be easily reduced to the calculation of the standard Dirichlet integral. Therefore, $$I=\frac{\pi}{2}\int_{b}^{\infty}e^{-y}dy=\frac{\pi}{2}e^{-b}.$$

-
+1: Very nice :-) –  Aryabhata Nov 8 '10 at 18:55
Very inspiring solution! I learned a lot. Thanks! –  Martin Gales Nov 9 '10 at 6:10
@Martin Gales: You're welcome. –  Andrey Rekalo Nov 9 '10 at 7:51

These are the methods I use to evaluate $$\int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx$$ and post it on Brilliant.org as a solution of similar problem. You can use the similar technique to evaluate $$\int_0^{\infty}\frac{\cos x}{x^2+1}\,dx.$$

Method 1:

Consider the function $f(t)=e^{-a|t|}$, then the Fourier transform of $f(t)$ is given by \begin{align} F(\omega)=\mathcal{F}[f(t)]&=\int_{-\infty}^{\infty}f(t)e^{-i\omega t}\,dt\\ &=\int_{-\infty}^{\infty}e^{-a|t|}e^{-i\omega t}\,dt\\ &=\int_{-\infty}^{0}e^{at}e^{-i\omega t}\,dt+\int_{0}^{\infty}e^{-at}e^{-i\omega t}\,dt\\ &=\lim_{u\to-\infty}\left. \frac{e^{(a-i\omega)t}}{a-i\omega} \right|_{t=u}^0-\lim_{v\to\infty}\left. \frac{e^{-(a+i\omega)t}}{a+i\omega} \right|_{0}^{t=v}\\ &=\frac{1}{a-i\omega}+\frac{1}{a+i\omega}\\ &=\frac{2a}{\omega^2+a^2}. \end{align} Next, the inverse Fourier transform of $F(\omega)$ is \begin{align} f(t)=\mathcal{F}^{-1}[F(\omega)]&=\frac{1}{2\pi}\int_{-\infty}^{\infty}F(\omega)e^{i\omega t}\,d\omega\\ e^{-a|t|}&=\frac{1}{2\pi}\int_{-\infty}^{\infty}\frac{2a}{\omega^2+a^2}e^{i\omega t}\,d\omega\\ \frac{\pi e^{-a|t|}}{a}&=\int_{-\infty}^{\infty}\frac{e^{i\omega t}}{\omega^2+a^2}\,d\omega.\tag1 \end{align} Now, rewrite $$\int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx=\frac{1}{2}\int_{-\infty}^{\infty}\frac{\mathbb{Re}\left(e^{2ix}\right)}{x^2+2^2}\,dx.\tag2$$ Comparing $(2)$ to $(1)$ yield $t=2$ and $a=2$. Thus, \begin{align} \int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx &=\frac{1}{2}\frac{\pi e^{-2\cdot|2|}}{2}\\ &=\frac{\pi}{4e^4}\\ \end{align} and $$\Large\color{blue}{\int_0^{\infty}\frac{\cos x}{x^2+1}\,dx=\frac{\pi}{2e}}.$$

Method 2:

Note that: $$\int_{y=0}^\infty e^{-(x^2+4)y}\,dy=\frac{1}{x^2+4},$$ therefore $$\int_{x=0}^\infty\int_{y=0}^\infty e^{-(x^2+4)y}\cos2x\,dy\,dx=\int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx$$ Rewrite $\cos2x=\Re\left(e^{-2ix}\right)$, then \begin{align} \int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx&=\int_{x=0}^\infty\int_{y=0}^\infty e^{-(x^2+4)y}\cos2x\,dy\,dx\\ &=\int_{y=0}^\infty\int_{x=0}^\infty e^{-(yx^2+2ix+4y)}\,dx\,dy\\ &=\int_{y=0}^\infty e^{-4y} \int_{x=0}^\infty e^{-(yx^2+2ix)}\,dx\,dy. \end{align} In general \begin{align} \int_{x=0}^\infty e^{-(ax^2+bx)}\,dx&=\int_{x=0}^\infty \exp\left(-a\left(\left(x+\frac{b}{2a}\right)^2-\frac{b^2}{4a^2}\right)\right)\,dx\\ &=\exp\left(\frac{b^2}{4a}\right)\int_{x=0}^\infty \exp\left(-a\left(x+\frac{b}{2a}\right)^2\right)\,dx\\ \end{align} Let $u=x+\frac{b}{2a}\;\rightarrow\;du=dx$, then \begin{align} \int_{x=0}^\infty e^{-(ax^2+bx)}\,dx&=\exp\left(\frac{b^2}{4a}\right)\int_{x=0}^\infty \exp\left(-a\left(x+\frac{b}{2a}\right)^2\right)\,dx\\ &=\exp\left(\frac{b^2}{4a}\right)\int_{u=0}^\infty e^{-au^2}\,du.\\ \end{align} The last form integral is Gaussian integral that equals to $\dfrac{1}{2}\sqrt{\dfrac{\pi}{a}}$. Hence $$\int_{x=0}^\infty e^{-(ax^2+bx)}\,dx=\frac{1}{2}\sqrt{\frac{\pi}{a}}\exp\left(\frac{b^2}{4a}\right).$$ Thus $$\int_{x=0}^\infty e^{-(yx^2+2ix)}\,dx=\frac{1}{2}\sqrt{\frac{\pi}{y}}\exp\left(\frac{(2i)^2}{4y}\right)=\frac{1}{2}\sqrt{\frac{\pi}{y}}\exp\left(-\frac{1}{y}\right).$$ Next $$\int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx=\frac{\sqrt{\pi}}{2}\int_{y=0}^\infty \frac{\exp\left(-4y-\frac{1}{y}\right)}{\sqrt{y}}\,dy.$$ In general \begin{align} \int_{y=0}^\infty \frac{\exp\left(-ay-\frac{b}{y}\right)}{\sqrt{y}}\,dy&=2\int_{v=0}^\infty \exp\left(-av^2-\frac{b}{v^2}\right)\,dv\\ &=2\int_{v=0}^\infty \exp\left(-a\left(v^2+\frac{b}{av^2}\right)\right)\,dv\\ &=2\int_{v=0}^\infty \exp\left(-a\left(v^2-2\sqrt{\frac{b}{a}}+\frac{b}{av^2}+2\sqrt{\frac{b}{a}}\right)\right)\,dv\\ &=2\int_{v=0}^\infty \exp\left(-a\left(v-\frac{1}{v}\sqrt{\frac{b}{a}}\right)^2-2\sqrt{ab}\right)\,dv\\ &=2\exp(-2\sqrt{ab})\int_{v=0}^\infty \exp\left(-a\left(v-\frac{1}{v}\sqrt{\frac{b}{a}}\right)^2\right)\,dv\\ \end{align} The trick to solve the last integral is by setting $$I=\int_{v=0}^\infty \exp\left(-a\left(v-\frac{1}{v}\sqrt{\frac{b}{a}}\right)^2\right)\,dv.$$ Let $t=-\frac{1}{v}\sqrt{\frac{b}{a}}\;\rightarrow\;v=-\frac{1}{t}\sqrt{\frac{b}{a}}\;\rightarrow\;dv=\frac{1}{t^2}\sqrt{\frac{b}{a}}\,dt$, then $$I_t=\sqrt{\frac{b}{a}}\int_{t=0}^\infty \frac{\exp\left(-a\left(-\frac{1}{t}\sqrt{\frac{b}{a}}+t\right)^2\right)}{t^2}\,dt.$$ Let $t=v\;\rightarrow\;dt=dv$, then $$I_t=\int_{t=0}^\infty \exp\left(-a\left(t-\frac{1}{t}\sqrt{\frac{b}{a}}\right)^2\right)\,dt.$$ Adding the two $I_t$s yields $$2I=I_t+I_t=\int_{t=0}^\infty\left(1+\frac{1}{t^2}\sqrt{\frac{b}{a}}\right)\exp\left(-a\left(t-\frac{1}{t}\sqrt{\frac{b}{a}}\right)^2\right)\,dt.$$ Let $s=t-\frac{1}{t}\sqrt{\frac{b}{a}}\;\rightarrow\;ds=\left(1+\frac{1}{t^2}\sqrt{\frac{b}{a}}\right)dt$ and for $0<t<\infty$ is corresponding to $-\infty<s<\infty$, then $$I=\frac{1}{2}\int_{s=-\infty}^\infty e^{-as^2}\,ds=\frac{1}{2}\sqrt{\frac{\pi}{a}}.$$ Thus \begin{align} \int_{y=0}^\infty \frac{\exp\left(-ay-\frac{b}{y}\right)}{\sqrt{y}}\,dy&=2\exp(-2\sqrt{ab})\int_{v=0}^\infty \exp\left(-a\left(v-\frac{1}{v}\sqrt{\frac{b}{a}}\right)^2\right)\,dv\\ &=\sqrt{\frac{\pi}{a}}e^{-2\sqrt{ab}}\\ \end{align} and \begin{align} \int_0^{\infty}\frac{\cos2x}{x^2+4}\,dx&=\frac{\sqrt{\pi}}{2}\int_{y=0}^\infty \frac{\exp\left(-4y-\frac{1}{y}\right)}{\sqrt{y}}\,dy\\ &=\frac{\sqrt{\pi}}{2}\cdot\sqrt{\frac{\pi}{4}}e^{-2\sqrt{4\cdot1}}\\ &=\frac{\pi}{4e^4}. \end{align} Hence $$\Large\color{blue}{\int_0^{\infty}\frac{\cos x}{x^2+1}\,dx=\frac{\pi}{2e}}.$$

-

The previous answer is not correct. If you use the Taylor expansion of cosine and integrate termwise you consider integrals of the following form: \begin{eqnarray} \int_{0}^{\infty} \frac{x^{a} \ dx}{1 + x^{2}} = \tfrac{\pi}{2} \sec (\tfrac{\pi a}{2}) \end{eqnarray} which is only well-defined if $-1 < a < 1$.

-


$$\mbox{Lets}\quad\fermi\pars{\mu}\equiv \half\int_{-\infty}^{\infty}{\cos\pars{\mu x} \over 1 + x^{2}}\dd x \quad\mbox{such that}\quad \left\lbrace\begin{array}{rcl} \int_{0}^{\infty}{\cos\pars{x} \over 1 + x^{2}}\dd x & = & \fermi\pars{1} \\[1mm] \fermi\pars{0} & = & {\pi \over 2} \end{array}\right.$$ \begin{align} \fermi''\pars{\mu}& =\half\int_{-\infty}^{\infty}{-x^{2}\cos\pars{\mu x} \over 1 + x^{2}}\dd x =-\pi\,\Re\int_{-\infty}^{\infty}\expo{\ic\mu x}\,{\dd x \over 2\pi} +\fermi\pars{\mu} \\[3mm]&\imp\quad\fermi''\pars{\mu} - \fermi\pars{\mu} = -\pi\,\delta\pars{\mu} \end{align}

The differential equation is equivalent to: $$\left\lbrace% \begin{array}{rcl} \fermi''\pars{\mu} - \fermi\pars{\mu} = 0 & \mbox{if} & \mu \not= 0 \\[2mm] \fermi'\pars{0^{+}} - \fermi'\pars{0^{-}} & = & -\pi \end{array}\right.$$

When $\ds{\mu \not= 0}$, the solutions are linear combinations of $\ds{\expo{\pm\mu}}$. Since $\ds{\fermi\pars{0} = {\pi \over 2}}$and the solution is continuos at $\ds{\mu = 0}$ and finite, we'll get: $$\fermi\pars{\mu} = {\pi \over 2}\,\expo{-\verts{\mu}}$$ It satisfies $\ds{\fermi'\pars{0^{+}} - \fermi'\pars{0^{-}} = \pars{-\,{\pi \over 2}} - \pars{{\pi \over 2}} = -\pi}$

$$\color{#44f}{\large% \int_{0}^{\infty}{\cos\pars{x} \over 1 + x^{2}}\dd x} =\fermi\pars{1} = {\pi \over 2}\,\expo{-\verts{1}}= \color{#44f}{\large{\pi \over 2\expo{}}}$$

-

You can try using the Taylor expansion of $\cos$.

-