How to evaluate $\int_{-\infty}^{\infty}dx \frac{x^2 e^x}{(e^x+1)^2}$

First off, notice the integrand is even, so we have $$ \int_{-\infty}^\infty \frac{x^2 e^x}{(e^x+1)^2}dx = 2\int_{0}^\infty \frac{x^2 e^x}{(e^x+1)^2}dx.$$ Then we can expand $$ \frac{1}{(1+x)^2} = \sum_{n=0}^\infty (-1)^{n}(n+1) x^n $$ and write $$ 2\int_{0}^\infty \frac{x^2 e^x}{(e^x+1)^2}dx=\\ =2\int_{0}^\infty \frac{x^2 e^{-x}}{(e^{-x}+1)^2}dx \\ = 2 \int_0^\infty x^2e^{-x}\sum_{n=0}^\infty (-1)^n (n+1) e^{-nx}\\=2\sum_{n=0}^\infty (-1)^n(n+1) \int_0^\infty x^2 e^{-(n+1)x}dx\\=4\sum_{n=0}^\infty \frac{(-1)^n}{(n+1)^2}.$$ Then we have $$ \sum_{n=0}^\infty \frac{(-1)^n}{(n+1)^2} = 1-\frac{1}{2^2} + \frac{1}{3^2}\ldots = (1-\frac{2}{2^2})(1+\frac{1}{2^2} + \frac{1}{3^2}\ldots) = \frac{\pi^2}{12}$$

Edit Realized this can be simplified somewhat by first doing an integration by parts $$ 2\int_0^\infty \frac{x^2 e^x}{(e^x+1)^2}dx = 4\int_0^\infty \frac{x}{e^x+1}dx$$ followed by a similar series expansion. Additionally, this solution somewhat 'misses the point' relative to contour integration approaches since that's one of the slicker ways to get $\sum_{n}1/n^2=\pi^2/6$ in the first place (and also transformation from the sums to integrals like this are the source of many zeta function identities).


Substitute $e^x=t$ we get $$I=\int_0^{\infty} \frac {\ln^2t dt}{(1+t)^2}$$

Let $$J(a)=\int_0^{\infty} \frac {t^{a-1}dt}{(1+t)^2}$$

So we need to find $J''(1)$

Notice that $$J(a)=B(a,2-a)=\frac {\Gamma(a)\Gamma(2-a)}{\Gamma(2)}$$

Where $B(x,y)$ is Standard beta function and $\Gamma(x)$ is the Gamma function

Using the properties of Gamma function and Euler's reflection formula we have $$J(a)=\Gamma(a) \cdot(1-a)\Gamma(1-a)=\pi \frac {1-a}{\sin \pi a}$$

Differentiating twice w.r.t $a$ and taking limit $a\to 1$ gives the desired result


You have $$ \int_{-\infty}^\infty\frac{x^2 e^x}{(e^x+1)^2}\,\mathrm{d}x= \int_{-\infty}^\infty\frac{x^2}{2(\cosh x+1)}\,\mathrm{d}x $$ So integrate $\dfrac{z^3}{1+\cosh z}$ around rectangle $\pm R\pm2\pi i$, we have encircled a simple pole at $\pi i$ with residue $6\pi^2$. The vertical sides contribution is $\to 0$ as $R\to\infty$ because of cosh in the denominator, and the horizontal contribution $$ \int_{-\infty}^\infty\frac{x^3}{1+\cosh x}\,\mathrm{d}x+\int_\infty^{-\infty}\frac{(x+2\pi i)^3}{1+\underbrace{\cosh(x+2\pi i)}_{=\cosh x}}\,\mathrm{d}x $$ whose imaginary part is $$ 2\pi\int_\infty^{-\infty}\frac{3x^2-4\pi^2}{1+\cosh(x)}\,\mathrm{d}x. $$ So $$ 3\int_\infty^{-\infty}\frac{x^2}{1+\cosh(x)}\,\mathrm{d}x -4\pi^2\int_\infty^{-\infty}\frac{1}{1+\cosh(x)}\,\mathrm{d}x =6\pi^2 $$ i.e., \begin{align} \int_{-\infty}^\infty\frac{x^2}{2(1+\cosh(x))}\,\mathrm{d}x &=-\pi^2 +\frac43\pi^2\int_{-\infty}^\infty\frac{1}{2(1+\cosh(x))}\,\mathrm{d}x \\ &=-\pi^2+\frac43\pi^2=\frac13\pi^2 \end{align} since $$ \int_{-\infty}^\infty\frac{1}{2(\cosh x+1)}\,\mathrm{d}x=\int_{-\infty}^\infty\frac14\operatorname{sech}^2\frac x2\,\mathrm{d}x=\left[\frac12\tanh\frac x2\right]_{-\infty}^\infty=1. $$