# Integrating $\int_0^\pi \frac{x\cos x}{1+\sin^2 x}dx$ [duplicate]

I am working on $\displaystyle\int_0^\pi \frac{x\cos x}{1+\sin^2 x}\,dx$

First: I use integrating by part then get

$$x\arctan(\sin x)\Big|_0^\pi-\int_0^\pi \arctan(\sin x)\,dx$$

then I have $\displaystyle -\int_0^\pi \arctan(\sin x)\,dx$ because $x\arctan(\sin x)\Big|_0^\pi$ is equal to $0$

However, I don't know how to integrate $\displaystyle -\int_0^\pi \arctan(\sin x)\,dx$

Can someone give me a hint?

Thanks

## marked as duplicate by user7530, Ahaan S. Rungta, user147263, Rory Daulton, k170Dec 27 '14 at 22:23

• I recall this to be a challenging integral that can be solved with some help of dilogarithms. The answer is $$\log^2(1+\sqrt{2})-\frac{\pi^2}{4}$$ – karvens Dec 26 '14 at 1:39
• @NajibIdrissi here are two exact duplicates. math.stackexchange.com/questions/296548/… and math.stackexchange.com/questions/323603/… – N3buchadnezzar Dec 26 '14 at 11:04
• I wish to register my disagreement with the duplicate labeling. The problem statements are completely different and are only related through an integration by parts, and that is being generous. If we were to label every integral on this site as being a duplicate of another related via integration by parts, then we have our work cut out for us. Further, the solution I offer was motivated by the statement of this particular problem, and is not shown in the other problem. – Ron Gordon Dec 26 '14 at 14:13
• I have reopened the question. If this question is a duplicate of the other marked question, then there are a lot more questions on this site that are duplicates. And I don't think anyone wants to go there. I sure don't. – Ron Gordon Dec 26 '14 at 15:24
• @N3buchadnezzar: Only the second of those two are a duplicate. The first one is much simpler. – Hans Lundmark Dec 27 '14 at 18:39

I will outline how this problem may be attacked using complex analysis. This is a surprisingly involved problem which I mistook for a much easier one in which the sines and cosines were reversed. But this is again a useful exercise in setting up a contour integral and applying the residue theorem. It is very satisfying to see that the correct result appears after all the analysis and manipulation.

First recognize that

$$\int_0^{\pi} dx \frac{x \cos{x}}{1+\sin^2{x}} = \left [\frac{\partial}{\partial \alpha} \int_0^{\pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}}\right ]_{\alpha=1}$$

The idea is to somehow stretch the integration interval over the unit circle. If we instead consider the integral

\begin{align}\int_0^{2 \pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}} &= \int_0^{\pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}}+\int_{\pi}^{2 \pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}} \\ &= (1+\cos{\pi \alpha}) \int_0^{\pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}}+\sin{\pi \alpha} \int_0^{\pi} dx \frac{\cos{\alpha x}}{1+\sin^2{x}}\end{align}

Note that the second integral on the RHS may be extended over $[-\pi,\pi]$ due to the evenness of the integrand.

We now have the desired integral expressed in terms of two integrals that now may be expressed in terms of an integral over the unit circle in the complex plane.

We consider the following integral:

$$i 4 \oint_{C_{\pm}} dz \frac{z^{1+\alpha}}{z^4-6 z^2+1}$$

where $C_{\pm}$ is a keyhole contour about the positive/negative real axis, traversing the unit circle counterclockwise, with semicircular detours about the respective poles about $\pm (\sqrt{2}-1)$. (For a similar setup, see this answer.)

For example, $C_-$ is the following contour

which is a modified keyhole contour about the negative real axis within the unit circle. The modification is a pair of semicircular bumps of radius $\epsilon$ about the point $z=-1+\sqrt{2}$. These bumps are necessary because the integrand has a pole within the unit circle on the chosen branch cut of the integrand (i.e., the negative real axis).

I will leave the parametrization of the contour integral to the reader for the time being. Using the residue theorem, we determine that

$$\int_0^{\pi} dx \frac{\sin{\alpha x}}{1+\sin^2{x}} = \frac{\pi}{2 \sqrt{2}} \left (\sqrt{2}-1 \right )^{\alpha} \sin{\pi \alpha} - 8 \sin^2{\frac{\pi \alpha}{2}} PV \int_0^1 dx \frac{x^{1+\alpha}}{x^4-6 x^2+1}$$

Taking the derivative and setting $\alpha=1$ on both sides, we find that

$$\int_0^{\pi} dx \frac{x \cos{x}}{1+\sin^2{x}} = -\frac12 \left (1-\frac1{\sqrt{2}} \right )\pi^2 - 8 PV \int_0^1 dx \frac{x^2 \log{x}}{x^4-6 x^2+1}$$

Now,

$$\frac{8 x^2}{x^4-6 x^2+1} = \left (1+\frac1{\sqrt{2}} \right ) \left (\frac1{x-(\sqrt{2}+1)}- \frac1{x+(\sqrt{2}+1)}\right ) \\ - \left (1-\frac1{\sqrt{2}} \right ) \left (\frac1{x-(\sqrt{2}-1)}- \frac1{x+(\sqrt{2}-1)}\right )$$

The integrals individually may be expressed in terms of polylogs:

$$\int_0^1 dx \frac{\log{x}}{x-(\sqrt{2}+1)} = \operatorname{Li}_2{(\sqrt{2}-1)}$$ $$\int_0^1 dx \frac{\log{x}}{x+(\sqrt{2}+1)} = \operatorname{Li}_2{(-(\sqrt{2}-1))}$$

$$PV \int_0^1 dx \frac{\log{x}}{x-(\sqrt{2}-1)} = \frac{\pi^2}{3} - \frac12 \log^2{(1+\sqrt{2})}- \operatorname{Li}_2{(\sqrt{2}-1)}$$

$$\int_0^1 dx \frac{\log{x}}{x+(\sqrt{2}-1)} = \operatorname{Li}_2{(-(\sqrt{2}+1))}$$

Then

$$8 PV \int_0^1 dx \frac{x^2 \log{x}}{x^4-6 x^2+1} = \left (1+\frac1{\sqrt{2}} \right ) \left [\operatorname{Li}_2{(\sqrt{2}-1)}- \operatorname{Li}_2{(-(\sqrt{2}-1))}\right ]\\ - \left (1-\frac1{\sqrt{2}} \right ) \left [\frac{\pi^2}{3} - \frac12 \log^2{(1+\sqrt{2})}- \operatorname{Li}_2{(\sqrt{2}-1)}-\operatorname{Li}_2{(-(\sqrt{2}+1))} \right ]$$

We apply the following identities for $z \lt 0$ and $0 \lt z \lt 1$ respectively:

$$\operatorname{Li}_2{(z)} + \operatorname{Li}_2{\left(\frac1{z}\right )} = -\frac{\pi^2}{6}-\frac12 \log^2{(-z)}$$

$$\operatorname{Li}_2{\left(\frac{1-z}{1+z}\right )} - \operatorname{Li}_2{\left(-\frac{1-z}{1+z}\right )} = \operatorname{Li}_2{(-z)}-\operatorname{Li}_2{(z)} + \frac{\pi^2}{4} + \log{z} \log{\left(\frac{1+z}{1-z}\right )}$$

In the first identity, let $z=-(\sqrt{2}-1)$; in the second identity, let $z=\sqrt{2}-1$. For the latter case, it is fortuitous that $z=(1-z)/(1+z)$. We get

$$\operatorname{Li}_2{(-(\sqrt{2}-1))}+\operatorname{Li}_2{(-(\sqrt{2}+1))}=-\frac{\pi^2}{6}-\frac12 \log^2{(\sqrt{2}+1)}$$

$$\operatorname{Li}_2{(\sqrt{2}-1)}-\operatorname{Li}_2{(-(\sqrt{2}-1))} = \frac{\pi^2}{8} - \frac12 \log^2{(\sqrt{2}+1)}$$

We may now start putting this altogether:

$$8 PV \int_0^1 dx \frac{x^2 \log{x}}{x^4-6 x^2+1} = \left (1+\frac1{\sqrt{2}} \right ) \left [\frac{\pi^2}{8} - \frac12 \log^2{(\sqrt{2}+1)}\right ]\\ - \left (1-\frac1{\sqrt{2}} \right ) \left [\frac{9 \pi^2}{24} + \frac12 \log^2{(\sqrt{2}+1)} \right ]$$

With just a little more arithmetic, we may finally conclude that

$$\int_0^{\pi} dx \frac{x \cos{x}}{1+\sin^2{x}} = \log^2{(\sqrt{2}+1)} - \frac{\pi^2}{4}$$

I will provide detail as to the evaluation of the contour integral by the residue theorem. Again, consider the above contour integral:

$$i 4 \oint_{C_-} dz \frac{z^{1+\alpha}}{z^4-6 z^2+1}$$

As one may see from the figure, this contour has 8 segments, the integrals over which I will now write out in detail. Let $z_0=\sqrt{2}-1$.

$$\int_{-\pi}^{\pi} d\phi \frac{e^{i \alpha \phi}}{1+\sin^2{\phi}} + i 4 e^{i \pi \alpha} \int_1^{z_0+\epsilon} dx \frac{x^{1+\alpha}}{x^4-6 x^2+1} \\ -4 \epsilon \int_{\pi}^0 d\phi \, e^{i \phi} \frac{(e^{i \pi} z_0 + \epsilon e^{i \phi})^{1+\alpha}}{ (-z_0+\epsilon e^{i \phi})^4– 6 (-z_0+\epsilon e^{i \phi})^2 + 1} + i 4 e^{i \pi \alpha} \int_{z_0-\epsilon}^{\epsilon} dx \frac{x^{1+\alpha}}{x^4-6 x^2+1} \\ - 4 \epsilon \int_{\pi}^{-\pi} d\phi \, e^{i \phi} \frac{\epsilon^{1+\alpha} e^{i (1+\alpha) \phi}}{\epsilon^4 e^{i 4 \phi} – 6 \epsilon^2 e^{i 2 \phi}+1} + i 4 e^{-i \pi \alpha} \int_{\epsilon}^{z_0-\epsilon} dx \frac{x^{1+\alpha}}{x^4-6 x^2+1} \\ -4 \epsilon \int_0^{-\pi} d\phi \, e^{i \phi} \frac{(e^{-i \pi} z_0 + \epsilon e^{i \phi})^{1+\alpha}}{ (-z_0+\epsilon e^{i \phi})^4– 6 (-z_0+\epsilon e^{i \phi})^2 + 1} + i 4 e^{-i \pi \alpha} \int_{z_0+\epsilon}^{1} dx \frac{x^{1+\alpha}}{x^4-6 x^2+1}$$

which is equal to, in the limit as $\epsilon \to 0$,

$$\int_{-\pi}^{\pi} d\phi \frac{e^{i \alpha \phi}}{1+\sin^2{\phi}} + i 4 e^{i \pi \alpha} PV \int_1^0 dx \frac{x^{1+\alpha}}{x^4-6 x^2+1} \\ + i 4 e^{-i \pi \alpha} PV \int_0^1 dx \frac{x^{1+\alpha}}{x^4-6 x^2+1} - \frac{\pi z_0^{\alpha}}{2 \sqrt{2}} \left (e^{i \pi \alpha} + e^{-i \pi \alpha} \right )$$

The contour integral is equal to $i 2 \pi$ times the residue at the pole $z=\sqrt{2}-1$, or $2 \pi z_0^{\alpha}/(2 \sqrt{2}) e^{i \pi \alpha}$. Thus, we have

$$\int_{-\pi}^{\pi} d\phi \frac{\cos{\alpha \phi}}{1+\sin^2{\phi}} = \frac{\pi}{\sqrt{2}} z_0^{\alpha} (1+\cos{\pi \alpha}) – 8 \sin{\pi \alpha} \, PV \int_0^1 dx \frac{x^{1+\alpha}}{x^4-6 x^2+1}$$

Using the contour $C_+$, we can find the value of the other integral:

$$\int_0^{2 \pi} d\phi \frac{\sin{\alpha \phi}}{1+\sin^2{\phi}} = \frac{\pi}{\sqrt{2}} z_0^{\alpha} \sin{\pi \alpha} (1+\cos{\pi \alpha}) – 8 \sin^2{\pi \alpha} \, PV \int_0^1 dx \frac{x^{1+\alpha}}{x^4-6 x^2+1}$$

The result follows.

• @Ron Gordon Thank you for sharing the link 'identities'! I had forgotten it! +1. I just gave another approach for the above integral. – Olivier Oloa Dec 26 '14 at 14:42

Split the integral at $\dfrac{\pi}{2}$, we get

\displaystyle \begin{align} \int_0^\pi \frac{x\cos x}{1+\sin^2 x}\,dx &= \int_0^{\pi/2} \frac{x\cos x}{1+\sin^2 x}\,dx + \int_{\pi/2}^{\pi} \frac{x\cos x}{1+\sin^2 x}\,dx \\ & = \int_0^{\pi/2} \frac{x\cos x}{1+\sin^2 x}\,dx - \int_0^{\pi/2} \frac{(x+\pi/2)\sin x}{1+\cos^2 x}\,dx \\ &= 2\int_0^{\pi/2} \frac{x\cos x}{1+\sin^2 x}\,dx - \pi\int_0^{\pi/2} \frac{\cos x}{1+\sin^2 x}\,dx \\ &= 2\int_0^{\pi/2} \frac{x\cos x}{1+\sin^2 x}\,dx - \frac{\pi^2}{4}\end{align}

At this point we can write the above integral:

$\displaystyle \int_0^{\pi/2} \frac{x\cos x}{1+\sin^2 x}\,dx = \frac{\pi^2}{8} - \int_0^{\pi/2} \tan^{-1} \sin x \,dx$

The later can be evaluated in many ways. See for example Here.

See integral representations of Legendre $\chi$-function.

Also sos440 blog entry has a very nice solution to the problem.

Let be

\begin{align} I=\int_0^\pi \frac{x\cos x}{1+\sin^2 x}\operatorname{d}x&=-\int_0^\pi \arctan(\sin x)\operatorname{d}x \\ &=-2\int_0^{\pi/2} \arctan(\sin x)\operatorname{d}x\\ &=-2\int_0^1\frac{\arctan t}{\sqrt{1-t^2}}\operatorname{d}t \end{align} Let $$\displaystyle I(a) = \int_{0}^{1} \frac{\arctan at}{\sqrt{1-t^{2}}} \ dt.$$

Differentiating under the integral,

\begin{align} I'(a) &= \int_{0}^{1} \frac{t}{(1+a^{2}t^{2})\sqrt{1-t^{2}}} \ dt \\ &= \frac{1}{a \sqrt{1+a^{2}}} \text{arctanh} \left( \frac{a}{\sqrt{1+a^{2}}} \right)\\ &= \frac{1}{a \sqrt{1+a^{2}}} \text{arcsinh}(a) . \end{align}

Integrating back,

\begin{align} I(1)-I(0) = I(1) &= \int_{0}^{1} \frac{\text{arcsinh}(a)}{a \sqrt{1+a^{2}}} \ da \\ &= - \text{arcsinh}(a) \text{arcsinh}(\frac{1}{a}) \Big|^{1}_{0} + \int_{0}^{1} \frac{\text{arcsinh}(\frac{1}{a})}{\sqrt{1+a^{2}}} \ da \\ &= - \text{arcsinh}^{2}(1) + \int_{0}^{1} \frac{\text{arcsinh}(\frac{1}{a})}{\sqrt{1+a^{2}}} \ da \\ &= - \ln^{2}(1+\sqrt{2}) + \int_{0}^{1} \frac{\text{arcsinh}(\frac{1}{a})}{\sqrt{1+a^{2}}} \ da . \end{align}

Now let $\displaystyle w = \frac{1}{a}$.

Then

$$I(1) = - \ln^{2}(1+\sqrt{2}) + \int_{1}^{\infty} \frac{\text{arcsinh}(w)}{w \sqrt{1+w^{2}}}$$

$$= - \ln^{2}(1+\sqrt{2}) + I(\infty) - I(1) .$$

Therefore,

\begin{align} I(1) &= - \frac{\ln^{2}(1+\sqrt{2})}{2} + \frac{I(\infty)}{2} \\ &= - \frac{\ln^{2}(1+\sqrt{2})}{2} + \frac{\pi}{4} \int_{0}^{1} \frac{1}{\sqrt{1-t^{2}}} \ dt \\ &= - \frac{\ln^{2}(1+\sqrt{2})}{2} + \frac{\pi^{2}}{8} . \end{align}

Finally $$\color{blue}{\int_0^\pi \frac{x\cos x}{1+\sin^2 x}\operatorname{d}x=-2I(1)=\ln^{2}(1+\sqrt{2})-\frac{\pi^{2}}{4}.}$$

• (+1) but I think this is very similar to what RV did here. – r9m Dec 26 '14 at 2:41
• Very nicely done! +1 – Travis Willse Dec 26 '14 at 3:06

Here is another approach.

The idea, in order to evaluate $$\int_0^{\pi}\frac{x \cos{x}}{1+\sin^2{x}} {\rm d}x ,$$ is to start with a Fourier series expansion of $\displaystyle \frac{1}{1+\sin^2{x}}$.

For $0\leq x \leq\pi$, we easily obtain

\begin{align} \frac{1}{1+\sin^2{x}} &= \Re \frac{1}{1-i\sin{x}}\\\\ &= \Re \frac{2e^{ix}}{2-(e^{ix}-1)^2}\\\\ &= \frac{\sqrt{2}}{2}+\frac{\sqrt{2}}{2}\sum_{n=2}^{\infty}\left(\sqrt{2}-1\right)^n(1+(-1)^n)\cos (nx) \tag2 \end{align} The series in $(2)$ is normally convergent on $[0,\pi]$, we are then allowed to integrate termwise: $$\int_0^{\pi}\frac{x \cos{x}}{1+\sin^2{x}} {\rm d}x =\frac{\sqrt{2}}{2}\sum_{n=2}^{\infty}(\sqrt{2}-1)^n(1+(-1)^n)\!\!\int_0^{\pi}\!\! x\cos{x}\cos (nx)x \:{\rm d}x. \tag3$$ The latter integral is classic, we write $$2\cos{x}\cos (nx)=\cos((n+1)x)+\cos((n-1)x)$$ then integrate twice by parts to get $$-2\int_0^{\pi} x\cos{x}\cos (nx)x \:{\rm d}x=\frac{1}{(n+1)^2}+\frac{1}{(n-1)^2},\quad n=2,3,\ldots. \tag4$$ It is easy to see that $$\sum_{n=2}^{\infty}(1+(-1)^n)\left(\frac{x^n}{(n+1)^2}+\frac{x^n}{(n-1)^2}\right)=\left(x+\frac1x\right)\left({\rm{Li}}_2(x)-{\rm{Li}}_2(-x)\right), \quad |x|<1,$$ where ${\rm{Li}}_2(\cdot)$ is the dilogarithm function. Now, putting $x:= \sqrt{2}-1$ in the preceding identity and using the following closed form $$\rm{Li}_2{(\sqrt{2}-1)}-\rm{Li}_2{(-(\sqrt{2}-1))} = \frac{\pi^2}{8} - \frac12 \log^2{(\sqrt{2}+1)}, \tag5$$ as previously explaned by Ron Gordon, gives easily

$$\int_0^{\pi}\frac{x \cos{x}}{1+\sin^2{x}} {\rm d}x =\log^2{(\sqrt{2}+1)}-\frac{\pi^2}{4}.$$

• Thanks for the credit. I should say that I always enjoy reading your answers, epitomes of simplicity, erudition, and cleverness. – Ron Gordon Dec 26 '14 at 15:05