Prove $\int_{0}^{2\pi}{x\sin^3(x)\over 1+\cos^2(x)}dx=2\pi-\pi^2$

Hint:

$$\begin{align} I &=\int_{0}^{2\pi}\frac{x\sin^{3}{\left(x\right)}}{1+\cos^{2}{\left(x\right)}}\,\mathrm{d}x\\ &=\int_{0}^{\pi}\frac{x\sin^{3}{\left(x\right)}}{1+\cos^{2}{\left(x\right)}}\,\mathrm{d}x+\int_{\pi}^{2\pi}\frac{x\sin^{3}{\left(x\right)}}{1+\cos^{2}{\left(x\right)}}\,\mathrm{d}x\\ &=\int_{0}^{\pi}\frac{x\sin^{3}{\left(x\right)}}{1+\cos^{2}{\left(x\right)}}\,\mathrm{d}x+\int_{0}^{\pi}\frac{\left(\pi+t\right)\sin^{3}{\left(\pi+t\right)}}{1+\cos^{2}{\left(\pi+t\right)}}\,\mathrm{d}t;~~~\small{\left[x-\pi=t\right]}\\ &=\int_{0}^{\pi}\frac{t\sin^{3}{\left(t\right)}}{1+\cos^{2}{\left(t\right)}}\,\mathrm{d}t-\int_{0}^{\pi}\frac{\left(\pi+t\right)\sin^{3}{\left(t\right)}}{1+\cos^{2}{\left(t\right)}}\,\mathrm{d}t\\ &=-\pi\int_{0}^{\pi}\frac{\sin^{3}{\left(t\right)}}{1+\cos^{2}{\left(t\right)}}\,\mathrm{d}t.\\ \end{align}$$


First we prove that $$I=\int\frac{\sin^{3}\left(x\right)}{1+\cos^{2}\left(x\right)}dx=\cos\left(x\right)-2\arctan\left(\cos\left(x\right)\right)dx+C. $$ We note that $$\int\frac{\sin^{3}\left(x\right)}{1+\cos^{2}\left(x\right)}dx=\int\frac{\sin(x)\left(1-\cos^{2}\left(x\right)\right)}{1+\cos^{2}\left(x\right)}dx $$ and taking $\cos\left(x\right)=u $ we get $$I=\int\frac{u^{2}-1}{u^{2}+1}du $$ and from here it is quite simple to conclude. So integrating by parts our integral we get $$\int_{0}^{2\pi}\frac{x\sin^{3}\left(x\right)}{1+\cos^{2}\left(x\right)}dx=-\pi^{2}+2\pi-\int_{0}^{2\pi}\cos\left(x\right)dx+2\int_{0}^{2\pi}\arctan\left(\cos\left(x\right)\right)dx $$ and we note trivially that $$\int_{0}^{2\pi}\cos\left(x\right)dx=0 $$ and now we recall that if a function is $T$ periodic and integrable then for all $a\in\mathbb{R} $ holds $$\int_{0}^{T}f\left(x\right)dx=\int_{a}^{T+a}f\left(x\right)dx $$ we have $$\int_{0}^{2\pi}\arctan\left(\cos\left(x\right)\right)dx=\int_{-\pi}^{\pi}\arctan\left(\cos\left(x\right)\right)dx $$ $$=\int_{0}^{2\pi}\arctan\left(\cos\left(y-\pi\right)\right)dy=-\int_{0}^{2\pi}\arctan\left(\cos\left(y\right)\right)dy $$ hence $$\int_{0}^{2\pi}\arctan\left(\cos\left(x\right)\right)dx=0. $$


Suppose we seek to evaluate $$J = \int_0^{2\pi} \frac{x\sin^3 x}{1+\cos^2 x} dx = \int_0^{2\pi} \frac{x\sin x (1-\cos^2 x)}{1+\cos^2 x} dx \\ = \int_0^{2\pi} \frac{x\sin x (-1-\cos^2 x)}{1+\cos^2 x} dx + 2\int_0^{2\pi} \frac{x \sin x}{1+\cos^2 x} dx \\ = - \int_0^{2\pi} x\sin x dx + 2\int_0^{2\pi} \frac{x \sin x}{1+\cos^2 x} dx \\ = [x\cos x - \sin x]_0^{2\pi} + 2\int_0^{2\pi} \frac{x \sin x}{1+\cos^2 x} dx \\ = 2\pi + 2\int_0^{2\pi} \frac{x \sin x}{1+\cos^2 x} dx = 2\pi + 2K.$$

Put $z = \exp(ix)$ so that $dz = i\exp(ix) dx$ and hence $\frac{dz}{iz} = dx$ to obtain $$\int_{|z|=1} \frac{(z-1/z)\log(z)/i/(2i)}{1+(z+1/z)^2/4} \frac{dz}{iz} \\ = - \frac{2}{i} \int_{|z|=1} \frac{(z-1/z)\log(z)}{4+(z+1/z)^2} \frac{dz}{z} \\ = - \frac{2}{i} \int_{|z|=1} \frac{(z^2-1)\log(z)}{4z^2+(z^2+1)^2} dz.$$

Call the integrand without the scalar $f(z).$ The integral must be purely imaginary because $K$ is real. Now the contour here is a circle $\Gamma_0$ of radius one starting at $z=1$ and making a counterclockwise turn around the center at the origin until returning to just below $z=1$. The branch of the logarithm has the branch cut on the positive real axis with argument from $0$ to $2\pi$. We now close this contour with a line segment $\Gamma_1$ from $0$ to $1$ just above the real axis and a a line segment $\Gamma_2$ from $1$ to $0$ just below the real axis, connected by a circle $\Gamma_3$ of radius $\epsilon$ around the origin, obtaining the closed contour $\Gamma$. This is like a keyhole contour except the large circle does not go to infinity. We thus have

$$\int_\Gamma f(z) \; dz = 2\pi i\sum_\rho \mathrm{Res}_{z=\rho} f(z)$$

where the sum is over the poles $\rho$ inside $\Gamma.$
In particular

$$\int_{\Gamma_0} f(z) \; dz = - \int_{\Gamma_{1,2}} f(z) \; dz - \int_{\Gamma_3} f(z) \; dz + 2\pi i\sum_\rho \mathrm{Res}_{z=\rho} f(z)$$

The contribution from $\Gamma_1$ and $\Gamma_2$ is

$$\int_0^1 \frac{(x^2-1)\log(x)}{4x^2+(x^2+1)^2} dx - \int_0^1 \frac{(x^2-1)(\log(x)+2\pi i)}{4x^2+(x^2+1)^2} dx \\ = - 2\pi i\int_0^1 \frac{x^2-1}{4x^2+(x^2+1)^2} dx.$$

Call this integrand $g(z).$ The poles here are at $$\rho_{0,1,2,3} = \pm i(\sqrt{2}\pm 1).$$ We have

$$g(z) = \sum_\rho \frac{1}{z-\rho} \mathrm{Res}_{z=\rho} g(z).$$

Integrating we get

$$\sum_\rho [\log(z-\rho)]_0^1 \mathrm{Res}_{z=\rho} g(z) = \sum_\rho \log\frac{\rho-1}{\rho} \mathrm{Res}_{z=\rho} g(z).$$

Computing the residues we have

$$\mathrm{Res}_{z=\rho} g(z) = \frac{\rho^2-1}{4\rho^3+12\rho}$$

obtaining

$$i/4 \times \left(\log(+1 + (1+\sqrt{2}) i) - \log(+1 - (1+\sqrt{2}) i) \\ + \log(+1 + (1-\sqrt{2}) i) - \log(+1 - (1-\sqrt{2}) i)\right) \\ = i/4 \times \log i = i/4\times i \pi/2 = - \frac{\pi}{8}.$$

Moving on to $\Gamma_3$ we get by the ML bound

$$\lim_{\epsilon\rightarrow 0} 2\pi\epsilon\times \frac{(\epsilon^2-1)\log\epsilon}{4\epsilon^2 + (\epsilon^2+1)^2} = 0.$$

We are ready to compute the residues at the poles of $f$, which are the same as those of $g$, all on the imaginary axis with the modulus given by the scalar $\sqrt{2}\pm 1.$ We see that $\rho_{0,1} = \pm i(\sqrt{2}-1)$ are inside the contour and the residues are

$$\frac{(\rho_{0,1}^2-1)\log\rho_{0,1}}{4\rho_{0,1}^3+12\rho_{0,1}}$$

which yields

$$- \frac{\pi}{8} + \frac{1}{4} \log(\sqrt{2}-1) i \quad\text{and}\quad \frac{3\pi}{8} - \frac{1}{4} \log(\sqrt{2}-1) i.$$

Collecting all the contributions we finally have

$$K = -\frac{2}{i} \times \left(2\pi i\times -\frac{\pi}{8} + 2\pi i\times\frac{\pi}{4}\right) = - 2 \times \left(-\frac{\pi^2}{4} + \frac{\pi^2}{2}\right) = - \frac{\pi^2}{2}.$$

The answer to the problem is thus given by

$$2\pi + 2K = 2\pi - \pi^2$$

as claimed.