# Integral $\int_{-\infty}^{\infty}\frac{x^{2}}{\cosh\left(x\right)}\,{\rm d}x$

• I need to compute the improper integral $$\int_{-\infty}^{\infty}\frac{x^{2}}{\cosh\left(x\right)}\,{\rm d}x$$ using contour integration and possibly principal values. Trying to approach this as I would normally approach evaluating an improper integral using contour integration doesn't work here, and doesn't really give me any clues as to how I should do it.
• This normal approach is namely evaluating the contour integral $$\oint_{C}{\frac{z^2}{\cosh\left(z\right)}\mathrm{d}z}$$ using a semicircle in the upper-half plane centered at the origin, but the semicircular part of this contour integral does not vanish since $$\cosh\left(z\right)$$ has period $$2\pi\mathrm{i}$$ and there are infinitely-many poles of the integrand along the imaginary axis given by $$-\pi\mathrm{i}/2 + 2n\pi\mathrm{i}$$ and $$\pi\mathrm{i}/2 + 2n\pi\mathrm{i}$$ for $$n \in \mathbb{Z}$$.
• The residues of the integrand at these simple poles are $$-\frac{1}{4}\mathrm{i}\pi^{2}\left(1 - 4n\right)^{2}$$ and $$\frac{1}{4}\mathrm{i}\left(4\pi n + \pi\right)^{2}$$, so that even when we add up all of the poles, we have the sum $$4\pi^{2}\mathrm{i}\sum_{n = 0}^{\infty}\,n$$, which clearly diverges.

Any hints would be greatly appreciated.

• I'm about to go to bed, so no time for details, but it looks like you should do a contour-shift. Integrate over the rectangle $-R,R,R+\pi i, -R+\pi i$, whose boundary encloses one pole. The integral over the line $\operatorname{Im} z = \pi$ reproduces a) the original integral, b) and odd part, and c) an integral $$\int_{-\infty}^\infty \frac{\pi^2}{\cosh x}\,dx$$ that can be dealt with by the same shift. Commented Mar 3, 2014 at 0:07
• That worked perfectly, thank you very much. You should make that an answer when you get the chance so I can accept it. Commented Mar 3, 2014 at 0:38

Integrals of the form

$$\int_{-\infty}^\infty \frac{p(x)}{\cosh x}\,dx,$$

where $p$ is a polynomial can be evaluated by shifting the contour of integration to a line $\operatorname{Im} z \equiv c$. We first check that the integrals over the vertical segments connecting the two lines tend to $0$ as the real part tends to $\pm\infty$:

$$\lvert \cosh (x+iy)\rvert^2 = \lvert \cosh x\cos y + i \sinh x\sin y\rvert^2 = \sinh^2 x + \cos^2 y,$$

so the integrand decays exponentially and

$$\left\lvert \int_{R}^{R + ic} \frac{p(z)}{\cosh z}\,dz\right\rvert \leqslant \frac{K\,c}{\sinh R}\left(R^2+c^2\right)^{\deg p/2} \xrightarrow{R\to \pm\infty} 0.$$

Since $\cosh \left(z+\pi i\right) = -\cosh z$, and the only singularity of the integrand between $\mathbb{R}$ and $\mathbb{R}+\pi i$ is a simple pole at $\frac{\pi i}{2}$ (unless $p$ has a zero there, but then we can regard it as a simple pole with residue $0$) with the residue

$$\operatorname{Res}\left(\frac{p(z)}{\cosh z};\, \frac{\pi i}{2}\right) = \frac{p\left(\frac{\pi i}{2}\right)}{\cosh' \frac{\pi i}{2}} = \frac{p\left(\frac{\pi i}{2}\right)}{\sinh \frac{\pi i}{2}} = \frac{p\left(\frac{\pi i}{2}\right)}{i},$$

the residue theorem yields

\begin{align} \int_{-\infty}^\infty \frac{p(x)}{\cosh x}\,dx &= 2\pi\, p\left(\frac{\pi i}{2}\right) + \int_{\pi i-\infty}^{\pi i+\infty} \frac{p(z)}{\cosh z}\,dz\\ &= 2\pi\, p\left(\frac{\pi i}{2}\right) - \int_{-\infty}^\infty \frac{p(x+\pi i)}{\cosh x}\,dx\\ &= 2\pi\, p\left(\frac{\pi i}{2}\right) - \sum_{k=0}^{\deg p} \frac{(\pi i)^k}{k!}\int_{-\infty}^\infty \frac{p^{(k)}(x)}{\cosh x}\,dx.\tag{1} \end{align}

Since $\cosh$ is even, only even powers of $x$ contribute to the integrals, hence we can from the beginning assume that $p$ is an even polynomial, and need only consider the derivatives of even order.

For a constant polynomial, $(1)$ yields

$$\int_{-\infty}^\infty \frac{dx}{\cosh x} = 2\pi - \int_{-\infty}^\infty \frac{dx}{\cosh x}\Rightarrow \int_{-\infty}^\infty \frac{dx}{\cosh x} = \pi.$$

For $p(z) = z^2$, we obtain

\begin{align} \int_{-\infty}^\infty \frac{x^2}{\cosh x}\,dx &= 2\pi \left(\frac{\pi i}{2}\right)^2 - \int_{-\infty}^\infty \frac{x^2}{\cosh x}\,dx - (\pi i)^2\int_{-\infty}^\infty \frac{dx}{\cosh x}\\ &= - \frac{\pi^3}{2} - \int_{-\infty}^\infty \frac{x^2}{\cosh x}\,dx + \pi^3, \end{align}

which becomes

$$\int_{-\infty}^\infty \frac{x^2}{\cosh x}\,dx = \frac{\pi^3}{4}.$$

Just for laughs, another way to use a rectangular contour involves considering the following integral

$$\oint_C dz \frac{z^2}{\sinh{z}}$$

where $C$ is the rectangle having vertices $\pm i \pi/2$ and $R \pm i \pi/2$. The contour integral is then equal to

$$i \int_0^R dx \frac{(x-i \pi/2)^2 + (x+i \pi/2)^2}{\cosh{x}} + i \int_{-\pi/2}^{\pi/2} dy \frac{(R+i y)^2}{\sinh{(R+i y)}} + \int_{-\pi/2}^{\pi/2} dy \frac{y^2}{\sin{y}}$$

Note that, in the last integral, we did not need to take the Cauchy principal value as the singularity was removed by the $y^2$ in the numerator. Thus, the last integral vanishes because the integrand is odd. The middle integral vanishes as $R \to \infty$. On the other hand, by Cauchy's theorem, the contour integral is zero for a lack of poles inside $C$. Thus,

$$i 2 \int_0^{\infty} dx \frac{x^2-\pi^2/4}{\cosh{x}} = i \int_{-\infty}^{\infty} dx \frac{x^2-\pi^2/4}{\cosh{x}}= 0$$

Using the fact that

$$\int_{-\infty}^{\infty} \frac{dx}{\cosh{x}} = \pi$$

we get

$$\int_{-\infty}^{\infty} dx \frac{x^2}{\cosh{x}} = \frac{\pi^3}{4}$$

• Ron, as always, a nice solution! +1 ... I posted a complementary way forward that uses a transformation followed by "ye ole keyhole" contour analysis. Hope you like it. ;-)) - Mark Commented Mar 8, 2016 at 23:45

And yet, in a third approach, we enforce the substitution $x\to \log(x)$ and write

\begin{align} \int_0^\infty \frac{x^2}{\cosh(x)}\,dx&=2\int_{1}^{+\infty}\frac{\log^2 x}{x^2+1}\,dx\\\\ &=2\int_0^1 \frac{\log^2 x}{x^2+1}\,dx\\\\ &= \int_{0}^{+\infty}\frac{\log^2 x}{x^2+1}\,dx \end{align}

Thus, the integral of interest can be expressed as

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

Next, we examine the integral $I$ as given by

$$I=\oint_C \frac{\log^3(z)}{z^2+1}\,dz$$

where $C$ is the classical key-hole contour that runs along both sides of the positive real axis. Since the integrand is analytic in and on $C$, except at the simple poles, $z=\pm i$, its value is given by the residue theorem as

\begin{align} I&=2\pi i \text{Res}\left(\frac{\log^3(z)}{z^2+1}, z=\pm i\right)\\\\ &=2\pi i\left(\frac{\log^3(e^{i\pi/2})}{2i}+\frac{\log^3(e^{i3\pi/2})}{-2i}\right)\\\\ &=\frac{13\pi^4}{4}\,i \tag 1 \end{align}

Then, we note that we can write $I$ as

\begin{align} I&=\int_0^\infty \frac{\log^3(x)-(\log(x)+i2\pi)^3}{x^2+1}\,dx\\\\ &=-i6\pi \int_0^\infty \frac{\log^2(x)}{x^2+1}\,dx\\\\ &+12\pi^2\int_0^\infty \frac{\log(x)}{x^2+1}\,dx\\\\ &+i8\pi^3\int_0^\infty \frac{1}{x^2+1}\,dx \tag 2 \end{align}

The first integral on the right-hand side of $(2)$ is $1/2$ the integral of interest, the second integral is $0$ (to see this, enforce the substitution $x\to 1/x$), and the third integral is

$$\int_0^\infty \frac{1}{x^2+1}=\pi/2 \tag 3$$

Using $(1)-(3)$ reveals

$$-i6\pi \int_0^\infty \frac{\log^2(x)}{x^2+1}\,dx=\frac{13\pi^4}{4}\,i -i4\pi^4$$

and therefore, we find that

$$\bbox[5px,border:2px solid #C0A000]{\int_{-\infty}^\infty \frac{x^2}{\cosh(x)}\,dx=\frac{\pi^3}{4}}$$

Here is another way to do it. Let $$I=\int_{-\infty}^{\infty} \frac{x^2}{\cosh(x)}dx=2\int_{0}^{\infty} \frac{x^2}{\cosh(x)}dx=4\int_{0}^{\infty} \frac{x^2}{e^x+e^{-x}}dx.$$ Let $x=\ln(u),dx=\frac{1}{u}du.$ We get : $$I=4\int_{1}^{\infty} \frac{(\ln(u))^2}{u^2+1}du.$$ But making another substitution $z=\frac{1}{u},dz=\frac{-1}{u^2}du$ shows $$\int_{1}^{\infty} \frac{(\ln(u))^2}{u^2+1}du=\int_{0}^{1} \frac{(\ln(z))^2}{z^2+1}dz.$$ If follows $$\int_{1}^{\infty} \frac{(\ln(u))^2}{u^2+1}du=\frac{1}{2}\int_{0}^{\infty} \frac{(\ln(u))^2}{u^2+1}du,$$ so $$I=2\int_{0}^{\infty} \frac{(\ln(u))^2}{u^2+1}du.$$

Now, we focus on finding $$\int_{0}^{\infty}\frac{(\ln(u))^2}{u^2+1}du.$$ We show this by considering the triple integral $$J=\int_{0}^{\infty}\int_{0}^{\infty}\int_{0}^{\infty} \frac{xy}{(1+x^2y^2z^2)(1+x^2)(1+y^2)}dzdydx.$$ and proving $J=I.$ Let us evaluate $J$ first. Recognizing that $$\int_{0}^{\infty} \frac{xy}{1+x^2y^2z^2}dz=\frac{\pi}{2},$$ we have $$J=\frac{\pi}{2} \int_{0}^{\infty}\int_{0}^{\infty}\frac{1}{1+x^2}\frac{1}{1+y^2}dydx=\frac{\pi^3}{8}.$$ Now we use Fubini's thoerem as such: $$J=\int_{0}^{\infty}\int_{0}^{\infty}\int_{0}^{\infty} \frac{xy}{(1+x^2y^2z^2)(1+x^2)(1+y^2)}dydzdx.$$ Integrating this way now, we find through partial fractions: $$J=\int_{0}^{\infty}\int_{0}^{\infty} \frac{\ln(xz)}{(x^2+1)(1-x^2z^2)}dzdx.$$ But $$\int_{0}^{\infty}\int_{0}^{\infty} \frac{\ln(xz)}{(x^2+1)(1-x^2z^2)}dzdx=\int_{0}^{\infty}\int_{0}^{\infty}\frac{\ln(x)}{(x^2+1)(1-x^2z^2)} +\frac{\ln(z)}{(x^2+1)(1-x^2z^2)}dzdx.$$ It turns out using partial fractions on both integrands, $$\int_{0}^{\infty}\int_{0}^{\infty}\frac{\ln(x)}{(x^2+1)(1-x^2z^2)}dzdx=0,$$ and $$\int_{0}^{\infty}\int_{0}^{\infty}\frac{\ln(x)}{(x^2+1)(1-x^2z^2)}dzdx=\int_{0}^{\infty}\int_{0}^{\infty}\frac{\ln(z)}{(x^2+1)(1-x^2z^2)}dxdz=\int_{0}^{\infty} \frac{(\ln(z))^2}{z^2+1}dz=I$$ So $$I=2\left(\frac{\pi^3}{8}\right),$$ which means $$I=\frac{\pi^3}{4}.$$

$$\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{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \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{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$$ \begin{align} &\bbox[5px,#ffd]{\int_{-\infty}^{\infty}{x^{2} \over \cosh\pars{x}}\,\dd x} = 4\int_{0}^{\infty}{x^{2}\expo{-x} \over 1 + \expo{-2x}}\,\dd x \\[5mm] = &\ 4\sum_{n = 0}^{\infty}\pars{-1}^{n} \int_{0}^{\infty}x^{2}\expo{-\pars{2n + 1}x}\,\,\,\dd x \\[5mm] = &\ 4\sum_{n = 0}^{\infty}{\pars{-1}^{n} \over \pars{2n + 1}^{3}} \int_{0}^{\infty}x^{2}\expo{-x}\,\,\,\dd x \\[5mm] = &\ 8\sum_{n = 0}^{\infty}{\pars{-1}^{n} \over \pars{2n + 1}^{3}} = -8\ic\sum_{n = 0}^{\infty}{\ic^{2n + 1} \over \pars{2n + 1}^{3}} \\[5mm] = &\ -8\ic\sum_{n = 1}^{\infty}{\ic^{n} \over n^{3}}\,{1 - \pars{-1}^{n} \over 2} \\[5mm] = &\ 8\,\Im\sum_{n = 1}^{\infty}{\ic^{n} \over n^{3}} = -4\ic\,\bracks{\on{Li}_{3}\pars{\ic} - \on{Li}_{3}\pars{-\ic}} \\[5mm] = &\ -4\ic\,\braces{\on{Li}_{3}\pars{\expo{2\pi\ic\bracks{\color{red}{1/4}}}} - \on{Li}_{3}\pars{\expo{-2\pi\ic\bracks{\color{red}{1/4}}}}} \\[5mm] = &\ -4\ic\bracks{-\,{\pars{2\pi\ic}^{3} \over 3!} \on{B}_{3}\pars{\color{red}{1 \over 4}}} \end{align}

The last expression is Jonqui$$\grave{\mrm{e}}$$re's Inversion Formula. $$\ds{\on{B}_{n}}$$ is a Bernoulli Polynomial. In particular, $$\ds{\on{B}_{3}\pars{x} = x^{3} - {3 \over 2}\,x^{2} + {1 \over 2}\,x}$$.

Finally, $$\bbox[5px,#ffd]{\int_{-\infty}^{\infty}{x^{2} \over \cosh\pars{x}}\,\dd x} = \bbx{\pi^{3} \over 4} \\$$

• In general, $\displaystyle\int_0^\infty \frac{x^{s-1}e^{-x}}{1+e^{-2x}}\, \mathrm dx=\beta(s)\cdot \Gamma(s)$ and in this case $\beta(3)=\frac{\pi^3}{32}$ and $\Gamma(3)=2!$. No need to evaluate further.
– user730361
Commented May 21, 2021 at 15:27

$$\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{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \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{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$$ \begin{align} &\!\bbox[5px,#ffd]{\int_{-\infty}^{\infty}{x^{2} \over \cosh\pars{x}}\,\dd x} = 4\int_{0}^{\infty}{\sinh\pars{x} \over \sinh\pars{2x}}\,x^{2}\,\dd x \\[5mm] \stackrel{x\ =\ t/4}{=}\,\,\,& {1 \over 16}\int_{0}^{\infty}{\sinh\pars{t/4} \over \sinh\pars{t/2}}\,t^{2}\,\dd t \\[5mm] = &\ \left.{1 \over 4}\,\partiald[2]{}{\alpha}\int_{0}^{\infty}{\sinh\pars{\alpha t/2} \over \sinh\pars{t/2}}\,\dd t \,\right\vert_{\,\alpha\ =\ 1/2} \\[5mm] = &\ \left.{1 \over 4}\,\partiald[2]{}{\alpha}\int_{0}^{\infty} {\expo{-\pars{1 - \alpha}t/2} - \expo{-\pars{1 + \alpha}t/2} \over 1 - \expo{-t}}\,\dd t\ \,\right\vert_{\,\alpha\ =\ 1/2} \\[5mm] = &\ {1 \over 4}\,\partiald[2]{}{\alpha}\left[% \int_{0}^{\infty}{\expo{-t} - \expo{-\pars{1 + \alpha}t/2} \over 1 - \expo{-t}}\,\dd t \right. \\[2mm] & \left.\phantom{{1 \over 4}\,\partiald[2]{}{\alpha}} -\int_{0}^{\infty}{\expo{-t} - \expo{-\pars{1 - \alpha}t/2} \over 1 - \expo{-t}}\,\dd t \right] _{\,\alpha\ =\ 1/2} \\[5mm] = &\ {1 \over 4}\,\partiald[2]{}{\alpha}\bracks{% \Psi\pars{1 + \alpha \over 2} - \Psi\pars{1 - \alpha \over 2}} _{\,\alpha\ =\ 1/2} \\[5mm] = &\ {1 \over 4}\,\partiald[2]{}{\alpha}\bracks{% \pi\cot\pars{\pi\,{1 - \alpha \over 2}}}_{\,\alpha\ =\ 1/2} \\[5mm] = &\ {\pi \over 4}\,\partiald[2]{}{\alpha}\bracks{% \tan\pars{\pi\alpha \over 2}}_{\,\alpha\ =\ 1/2} \\[5mm] = &\ {\pi \over 4}\bracks{% {\pi^{2} \over 4}\sec^{2}\pars{\pi a \over 2} \tan\pars{\pi a \over 2}}_{\,\alpha\ =\ 1/2} \\[5mm] = &\ {\pi^{3} \over 8}\ \underbrace{\sec^{2}\pars{\pi \over 4}}_{\ds{2}}\ \underbrace{\tan\pars{\pi \over 4}}_{\ds{1}} \\[5mm] = &\ \bbx{\pi^{3} \over 4} \\ & \end{align}