9

So I'm having trouble computing this integral:

$$\int_{-\infty}^\infty \frac{\cos(x)}{x^2+1}dx$$

After seeing some other answers on this website, I've realized that many people are using residues to get an answer. However, I know nothing about complex analysis, so I wanted to know if there is a better way of doing it without it.

I started by finding the indefinite integral which is:

$$-\dfrac{\sinh\left(1\right)\left(\operatorname{Si}\left(x+\mathrm{i}\right)+\operatorname{Si}\left(x-\mathrm{i}\right)\right)-\mathrm{i}\cosh\left(1\right)\left(\operatorname{Ci}\left(x+\mathrm{i}\right)-\operatorname{Ci}\left(x-\mathrm{i}\right)\right)}{2}$$

but finding what this function comes out to when finding the limit of it towards $\infty$ and $-\infty$ I get $-\pi\sinh(1)$

Now, I could be very wrong with both the indefinite integral and the value. Am I doing something wrong? Am I forgetting to take into account something I should be? Thanks in advanced!

Harry Peter
  • 8,193
Tom Himler
  • 2,384
  • Your antiderivative seems fine. And if we denote this by $I(x)$ with aid of Mathematica, it indeed yields the correct value as we have $$ \lim_{x\to\infty}I(x) = -\frac{\pi}{2}\sinh 1, \qquad \lim_{x\to-\infty} I(x) = \frac{\pi}{2}\sinh 1 - \pi \cosh 1. $$ So my bet is that you forgot to take the branch cut of $\operatorname{Ci}$ into consideration – Sangchul Lee Nov 05 '17 at 01:01
  • @SangchulLee Huh, that's odd, do you know how to come about with the answer for the one with x approaching negative infinity? Also, I'm pretty sure I took account of the branch cut of Ci – Tom Himler Nov 05 '17 at 01:09
  • In fact the best explanation for this comes from complex analysis. The extra factor appears when the contour crosses the singularity of $\frac{\cos z}{z}$ at $z = 0$. I am currently working to find an explanation that does not use complex analysis. – Sangchul Lee Nov 05 '17 at 01:16
  • Here is one explanation: for $x \in \mathbb{R}$ we have $$ \operatorname{Ci}(x\pm i) = \operatorname{Ci}(-x\mp i) - \operatorname{Ci}(\mp i) + \operatorname{Ci}(\pm i). $$ So if you know that $\operatorname{Ci}(x\pm i) \to 0$ as $x\to\infty$, it follows that $\operatorname{Ci}(x\pm i) \to \pm (\operatorname{Ci}(i) - \operatorname{Ci}(-i))$ as $x\to-\infty$. Now the answer follows from $$\operatorname{Ci}(i) - \operatorname{Ci}(-i) = i\pi. $$ – Sangchul Lee Nov 05 '17 at 01:48
  • @SangchulLee That's interesting, because actually replacing $i\pi$ for the definite integral calculation, it still doesn't seem to give $\frac{\pi}{e}$ Also want to preface that I'm still probably doing it wrong. – Tom Himler Nov 05 '17 at 02:00
  • Summarizing the computation we get $$ \lim_{x\to-\infty} I(x) = -\frac{\pi}{2}\sinh 1 + i (\operatorname{Ci}(i) - \operatorname{Ci}(-i)) \cosh 1. $$ This matches the result I describe above, given we know that $\operatorname{Ci}(i) - \operatorname{Ci}(-i) = i\pi$ holds. Then the integral equals $$ \pi (\cosh 1 - \sinh 1) = \frac{\pi}{e}. $$ – Sangchul Lee Nov 05 '17 at 02:05

6 Answers6

15

Here's a much nicer way using the standard differentiation under the integral sign technique. Let's first consider the general case$$I(a)=\int\limits_{-\infty}^{\infty}\frac {\cos ax}{1+x^2}\, dx$$Through integration by parts on $u=1/(1+x^2)$ and $dv=\cos ax\, dx$, we have$$a\cdot I(a)=2\int\limits_{-\infty}^{\infty}\frac {x\sin ax}{(1+x^2)^2}\, dx$$Differentating with respect to $a$, we obtain$$a\cdot I'(a)+I(a)=2I(a)-2\int\limits_{-\infty}^{\infty}\frac {\cos ax}{(1+x^2)^2}\, dx$$Combining like terms, we realize that the right-hand side is similar to what we obtained before. So differentiating (again), we finally see that$$a\cdot I''(a)=-2\int\limits_{-\infty}^{\infty}\frac {x\sin ax}{(1+x^2)^2}\, dx=a\cdot I(a)$$Solving the simple differential equation that follows, the general solution is $I(a)=C_1e^{a}+C_2e^{-a}$. When we set $a=0$, we see that $C_1=0$ and similarly, $C_2=\pi$ for $a\to\infty$. Therefore, the general solution is$$\int\limits_{-\infty}^{\infty}\frac {\cos ax}{1+x^2}\, dx=\color{blue}{\frac {\pi}{e^{|a|}}}$$

Crescendo
  • 4,417
  • A way of using the Feynman's Trick would really clarify actually if you could do that. – Tom Himler Nov 05 '17 at 01:16
  • @TomHimler That's the problem. I'm not sure what's supposed to be the correct substitution. I have a gut-feeling that it can be integrated using Feynman's trick, probably because I've seen a variant somewhere where differentiation can be used, but I'm not sure. I will update the answer as I make progress. – Crescendo Nov 05 '17 at 01:17
  • I would really appreciate it if you can. In the meantime, I'll try to see if I can do it as well. – Tom Himler Nov 05 '17 at 01:18
  • @TomHimler I think I've got it. Although it does involve a little bit of differential equations, namely solving$$I''(a)-I(a)=0$$You can do that, right? – Crescendo Nov 05 '17 at 01:27
  • Yes, thank you, I really appreciate the effort you've made to help me. – Tom Himler Nov 05 '17 at 01:33
  • @TomHimler No problem! Happy to help! :) – Crescendo Nov 05 '17 at 01:33
  • @TomHimler I had presented a way forward using Feynman's Trick Directly. I'm unsure whether that development was what you had in mind. – Mark Viola Apr 05 '21 at 15:55
  • The final answer is correct, revealing that the integral is not differentiable at $a = 0$, which is not at all obvious from the definition of $I(a)$. This means the method of determining $C_1$ at the end by setting $a = 0$ is invalid. Even if you want to let $a \to 0^+$, you need to prove $I(a)$ is continuous at $a = 0$. And you need to prove $I(a) = C_1e^a + C_2e^{-a}$ when $I''(a) = I(a)$ using only $a > 0$ (or only $a < 0$). This is discussed in Section 14 of https://kconrad.math.uconn.edu/blurbs/analysis/diffunderint.pdf starting on the second half of page 22. – KCd Feb 19 '25 at 02:30
  • @KCd For all $\delta>0$, the integral $I(a)$ is indeed differentiable for all $|a|>\delta>0$ owing to the uniform convergence of the improper integral of the derivative. And $I(a)$ is continous at $a=0$. Hence, $\lim_{a\to 0^\pm}I(a)=\lim_{a\to 0^\pm})\left(C_1e^a+C_2e^{-a} \right)=C_1+C_2$. And so on ... This technique is valid! – Mark Viola Feb 19 '25 at 23:51
7

Do you know the Fourier inversion theorem ? $$\frac{2}{1+x^2} = \int_{-\infty}^\infty e^{-|t|}e^{i x t}dt$$ where $\frac{d}{dt} e^{-|t|} \in L^1$ thus $$\int_{-\infty}^\infty \frac{2 e^{-i xu}}{1+x^2}dx = \lim_{A \to \infty} \int_{-A}^A e^{-ixu} (\int_{-\infty}^\infty e^{-|t|}e^{i x t}dt)dx=\lim_{A \to \infty}\int_{-\infty}^\infty e^{-|t|} A\frac{\sin(A(t-u))}{A(t-u)}dt$$ which converges to $2\pi e^{-|u|}$ by integration by parts

reuns
  • 79,880
7

Step 1. Let $s > 0$ and $\beta \in \mathbb{C}$. Then using the gaussian integral $\int_{-\infty}^{\infty} e^{-sx^2} \, dx = \sqrt{\pi/s}$, we have

\begin{align*} \int_{-\infty}^{\infty} e^{-s(x-\beta)^2} \, dx &= \int_{-\infty}^{\infty} \bigg( e^{-sx^2} + \int_{0}^{1} \overbrace{ 2s\beta(x-\beta t) e^{-s(x-\beta t)^2} }^{= \frac{\partial}{\partial t} e^{-s(x-\beta t)^2}} \, dt \bigg) \, dx \\ &= \sqrt{\frac{\pi}{s}} -\beta \int_{0}^{1} \int_{-\infty}^{\infty} (-2s)(x-\beta t) e^{-s(x-\beta t)^2} \, dx dt \quad {\small(\because\text{Fubini})}\\ &= \sqrt{\frac{\pi}{s}} -\beta \int_{0}^{1} \left[ e^{-s(x-\beta t)^2} \right]_{x=-\infty}^{x=\infty} \, dt = \bbox[border:1px dashed green,6px]{ \sqrt{\frac{\pi}{s}} }. \end{align*}

Then plugging $\beta=\pm\mathrm{i}/2s$, we check that

$$ \int_{-\infty}^{\infty} e^{-sx^2}\cos(x) \, dx = \sqrt{\frac{\pi}{s}} e^{-1/4s}. $$

Step 2. Using the previous step,

\begin{align*} I := \int_{-\infty}^{\infty} \frac{\cos x}{x^2+1} \, dx &= \int_{-\infty}^{\infty} \cos x \left( \int_{0}^{\infty} e^{-(x^2+1)s} \, ds \right) \, dx \\ &= \int_{0}^{\infty} \left( \int_{-\infty}^{\infty} e^{-sx^2}\cos(x) \, dx \right) e^{-s} \, ds \quad {\small(\because\text{Fubini})}\\ &= \int_{0}^{\infty} \sqrt{\frac{\pi}{s}} e^{-\left( s + \frac{1}{4s}\right)} \, ds \\ &= \int_{0}^{\infty} \sqrt{2\pi} e^{-\frac{1}{2}\left( t^2 + \frac{1}{t^2}\right)} \, dt. \quad {\small(2s=t^2)} \end{align*}

Finally here is a very slick way of computing the last integral. Applying the substitution $t\mapsto 1/t$ shows that

$$ \int_{0}^{\infty} e^{-\frac{1}{2}\left( t^2 + \frac{1}{t^2}\right)} \, dt = \int_{0}^{\infty} \frac{1}{t^2} e^{-\frac{1}{2}\left( t^2 + \frac{1}{t^2}\right)} \, dt. $$

So averaging,

$$ I = \sqrt{\frac{\pi}{2}} \int_{0}^{\infty} \left(1 + \frac{1}{t^2}\right) e^{-\frac{1}{2}\left( t - \frac{1}{t}\right)^2 - 1} \, dt. $$

Finally, applying the substitution $u = t - \frac{1}{t}$ proves

$$ I = \sqrt{\frac{\pi}{2}} \int_{-\infty}^{\infty} e^{-\frac{u^2}{2} - 1} \, du = \frac{\pi}{e}. $$

Sangchul Lee
  • 181,930
6

Let $f(a)$ be given by the convergent improper integral

$$f(a)=\int_0^\infty \frac{\cos(ax)}{x^2+1}\,dx \tag1$$

Since the integral $\int_0^\infty \frac{x\sin(ax)}{x^2+1}\,dx$ is uniformly convergent for $|a|\ge \delta>0$, we may differentiate under the integral in $(1)$ for $|a|>\delta>0$ to obtain

$$\begin{align} f'(a)&=-\int_0^\infty \frac{x\sin(ax)}{x^2+1}\,dx\\\\ &=-\int_0^\infty \frac{(x^2+1-1)\sin(ax)}{x(x^2+1)}\,dx\\\\ &=-\int_0^\infty \frac{\sin(ax)}{x}\,dx+\int_0^\infty \frac{\sin(ax)}{x(x^2+1)}\,dx\\\\ &=-\frac{\pi}{2}+\int_0^\infty \frac{\sin(ax)}{x(x^2+1)}\,dx\tag2 \end{align}$$

Again, since the integral $\int_0^\infty \frac{\cos(ax)}{x^2+1}\,dx$ converges uniformly for all $a$, we may differentiate under the integral in $(2)$ to obtain

$$f''(a)=\int_0^\infty \frac{\cos(ax)}{x^2+1}\,dx=f(a)\tag 3$$

Solving the second-order ODE in $(3)$ reveals

$$f(a)=C_1 e^{a}+C_2 e^{-a}$$

Using $f(0)=\pi/2$ and $f'(0)=-\pi/2$, we find that $C_1=0$ and $C_2=\frac{\pi}{2}$ and hence $f(a)=\frac{\pi e^{-a}}{2}$. Setting $a=1$ and exploiting even symmetry yields the coveted result

$$\bbox[5px,border:2px solid #C0A000]{\int_{-\infty}^\infty \frac{\cos(x)}{x^2+1}\,dx=\frac{\pi}{e}}$$

as expected!

Mark Viola
  • 184,670
3

$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{{\displaystyle #1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\iverson}[1]{\left[\left[\,{#1}\,\right]\right]} \newcommand{\on}[1]{\operatorname{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\sr}[2]{\,\,\,\stackrel{{#1}}{{#2}}\,\,\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$ $$ \begin{array}{c} \ds{\color{#44f}{\int_{-\infty}^{\infty}{\cos\pars{x} \over x^{2} + 1}\dd x}:\ \substack{\mbox{How to evaluate it} \\[2mm] \ds{\underline{\color{red}{\rm without}}}\ \ds{Residues\ Theorem\ ?.}}} \\ ------------------------ \end{array} $$ \begin{align*} & \mbox{Lets}\ \left\{\begin{array}{rcl} \ds{\on{y}\pars{t}} & \ds{\equiv} & \ds{\int_{-\infty}^{\infty}{\cos\pars{tx} \over x^{2} + 1}\dd x} \\[2mm] \ds{\on{y}\pars{0}} & \ds{=} & \ds{\pi} \end{array}\right. \\[5mm] & \mbox{where}\ \ddot{\on{y}}\pars{t} = -2\pi\,\delta\pars{t} + \on{y}\pars{t} \\[5mm] & \mbox{Note that}\ \on{y}\pars{t}\ \mbox{is an}\ \underline{even}\ \mbox{function of}\ t. \\[5mm] \mbox{In addition,}\ & \ \ddot{\on{y}}\pars{t} - \on{y}\pars{t} = -2\pi\,\delta\pars{t} \\[5mm] \implies & \on{y}\pars{t} = \left\{\begin{array}{rl} \ds{a\sinh\pars{t} + \pi\cosh\pars{t},} & \ds{t < 0} \\[1mm] \ds{-a\sinh\pars{t} + \pi\cosh\pars{t},} & \ds{t > 0} \end{array}\right.\quad \\[2mm] & \mbox{and}\quad \left.\lim_{\epsilon\ \to\ 0^{+}}\ \on{y}'\pars{t}\right\vert_{-\epsilon}^{\phantom{-}\epsilon} = -2\pi \end{align*} \begin{align*} -2\pi = \pars{-a} - a \implies a = \pi \end{align*} Therefore, \begin{align*} & \color{#44f}{\int_{-\infty}^{\infty}{\cos\pars{x} \over x^{2} + 1}\dd x} = \on{y}\pars{1} = -\pi\sinh\pars{1} + \pi\cosh\pars{1} \\[5mm] = & \ \bbx{\color{#44f}{\large\pi\expo{-1}}} \approx 1.1557 \\ & \end{align*}

Felix Marin
  • 94,079
1

$$x^2+1 = \left(x-i\right)\left(x+i\right)$$

$$A\left(x-i\right)+B\left(x+i\right) =e^{ix}+e^{-ix}$$

$$A=-\frac{e^{ix}+e^{-ix}}{2i}$$

$$-\frac{1}{2i}\left[\int_{-\infty}^{\infty} \frac{e^{ix}}{x-i}dx+\int_{-\infty}^{\infty}\frac{e^{-ix}}{x-i}\right]$$

$$u=x-i, \quad x=u+i$$

$$-\frac{1}{2i}\left[e^1\int_{-\infty}^{\infty} \frac{e^{iu}}{u}du+e^{-1}\int_{-\infty}^{\infty}\frac{e^{-iu}}{u}du\right]=\frac{\pi}{e}$$ $$B=\frac{e^{ix}+e^{-ix}}{2i}$$

$$\frac{1}{2i}\left[\int_{-\infty}^{\infty} \frac{e^{ix}}{x+i}dx+\int_{-\infty}^{\infty}\frac{e^{-ix}}{x+i}\right]$$

$$u=x+i, \quad x=u-i$$

$$\frac{1}{2i}\left[e^1\int_{-\infty}^{\infty} \frac{e^{iu}}{u}dx+e^{-1}\int_{-\infty}^{\infty}\frac{e^{-iu}}{u}\right]=\frac{\pi}{e}$$

$$\frac{A}{2\left(x-i\right)}+\frac{B}{2\left(x+i\right)} = \cos\left(x\right)$$

$$\frac{1}{2}\left[-\int_{-\infty}^{\infty}\frac{e^{ix}+e^{-ix}}{2i\left(x-i\right)}+\int_{-\infty}^{\infty}\frac{e^{ix}+e^{-ix}}{2i\left(x+1\right)}\right] = \frac{\pi}{e}$$

$$\boxed{\int_{-\infty}^{\infty}\frac{\cos\left(x\right)}{x^2+1}dx=\frac{\pi}{e}}$$

Daniel K
  • 320