How does one integrate $x^2 \frac{e^x}{(e^x+1)^2}$?

Here, we present an approach that uses "Feynmann's Trick" for differentiating under the integral along with Contour Integration.

Let $I$ be the integral given by

$$I=\int_{-\infty}^\infty \frac{x^2e^x}{(e^x+1)^2}\,dx$$


"FEYNMANN'S TRICK"

Enforcing the substitution $x\to \log(x)$ reveals

$$\begin{align} I&=\int_0^\infty \frac{\log^2(x)}{(x+1)^2}\,dx\\\\ &=\bbox[5px,border:2px solid #C0A000]{\left.\left(\frac{d^2}{da^2}\int_0^\infty \frac{x^a}{(x+1)^2}\,dx\right)\right|_{a=0}} \tag 1 \end{align}$$


CONTOUR INTEGRATION

To evaluate the integral in $(1)$, we move to the complex plane and analyze the closed-contour integral $J(a)$ given by

$$\bbox[5px,border:2px solid #C0A000]{J(a)=\oint_C \frac{z^a}{(1+z)^2}\,dz} \tag 2$$

where $C$ is the classical "key-hole" contour along the branch cut extending from the origin along the non-negative real axis.


Evaluation Using the Residue Theorem

From the Residue Theorem, $J(a)$ is given by

$$\begin{align} J(a)&=2\pi i \text{Res}\left(\frac{z^a}{(1+z)^2}, z=-1\right)\\\\ &=2\pi i \left.\frac{d}{dz}\left((1+z)^2\frac{z^a}{(1+z)^2}\right)\right|{z=-1}\\\\ &=\bbox[5px,border:2px solid #C0A000]{-2\pi i a e^{i\pi a}} \tag 2 \end{align}$$


Decomposing $J(a)$

Next, we write $J(a)$ as

$$\begin{align} J(a)&=\int_0^\infty \frac{x^a}{(1+x)^2}\,dx-\int_0^\infty \frac{x^ae^{i2\pi a}}{(1+x)^2}\,dx\\\\ &=\bbox[5px,border:2px solid #C0A000]{(1-e^{i2\pi a})\int_0^\infty \frac{x^a}{(1+x)^2}\,dx} \tag 3 \end{align}$$


PUTTING THINGS TOGETHER

From $(2)$ and $(3)$ we see that

$$\bbox[5px,border:2px solid #C0A000]{\int_0^\infty \frac{x^a}{(1+x)^2}\,dx=\frac{\pi a}{\sin(\pi a)}} \tag 4$$


FINISHING IT OFF

Finally, using $(4)$ in $(1)$ reveals

$$\begin{align} I&=\left.\left(\frac{d^2}{da^2}\frac{\pi a}{\sin(\pi a)}\right)\right|_{a=0}\\\\ &=\lim_{a\to 0}\left(\frac{\pi^3 a(1+\cos^2(\pi a))-2\pi^2 \cos(\pi a)\sin(\pi a)}{\sin^3(\pi a)}\right)\\\\\ &=\frac{\pi^2}{3} \end{align}$$

as was to be shown!


We have $$\frac d{dx}\frac1{e^x+1}=\frac{-e^x}{(e^x+1)^2}$$ Also $$\frac{e^x}{(e^x+1)^2}=\frac{e^{-x}}{(1+e^{-x})^2}$$ So $$\begin{align}\int_{-\infty}^{\infty}x^2\frac{e^x}{(e^x+1)^2}dx&=2\int_0^{\infty}x^2\frac{e^x}{(e^x+1)^2}dx=-2\int_0^{\infty}x^2\frac d{dx}\frac1{e^x+1}dx\\ &=\left.-2x^2\frac1{e^x+1}\right|_0^{\infty}+4\int_0^{\infty}\frac x{e^x+1}dx\\ &=0+4\int_0^{\infty}\frac{xe^{-x}}{e^{-x}+1}dx=4\sum_{k=0}^{\infty}(-1)^k\int_0^{\infty}xe^{-(k+1)x}dx\\ &=4\sum_{k=0}^{\infty}(-1)^k \frac{\Gamma(2)}{(k+1)^2}=4\sum_{k=1}^{\infty}\frac{(-1)^{k+1}}{k^2}\\ &=4\left(1-\frac24\right)\zeta(2)=2\frac{\pi^2}6=\frac{\pi^2}3\end{align}$$


Another approach. We have $$\int_{-\infty}^{\infty}\frac{x^{2}e^{x}}{\left(e^{x}+1\right)^{2}}dx=2\int_{0}^{\infty}\frac{x^{2}e^{x}}{\left(e^{x}+1\right)^{2}}dx=2\int_{0}^{\infty}\frac{x^{2}}{e^{x}+1}dx-2\int_{0}^{\infty}\frac{x^{2}}{\left(e^{x}+1\right)^{2}}dx. $$ The first integral is classical $$2\int_{0}^{\infty}\frac{x^{2}}{e^{x}+1}dx=2\sum_{k\geq0}\left(-1\right)^{k}\int_{0}^{\infty}x^{2}e^{-x\left(k+1\right)}dx $$ $$=4\sum_{k\geq0}\frac{\left(-1\right)^{k}}{\left(k+1\right)^{3}}=3\zeta\left(3\right) $$ and in a similar way we can compute the other integral $$2\int_{0}^{\infty}\frac{x^{2}}{\left(e^{x}+1\right)^{2}}dx=2\sum_{k\geq0}k\left(-1\right)^{k-1}\int_{0}^{\infty}x^{2}e^{-x\left(k+1\right)}dx $$ $$=4\sum_{k\geq0}\frac{k\left(-1\right)^{k-1}}{\left(k+1\right)^{3}}=-\frac{\pi^{2}}{3}+3\zeta\left(3\right) $$ hence $$\int_{-\infty}^{\infty}\frac{x^{2}e^{x}}{\left(e^{x}+1\right)^{2}}dx=\frac{\pi^{2}}{3}$$ as wanted.