# A difficult integral evaluation problem

How do I compute the integration for $a>0$,

$$\int_0^\pi \frac{x\sin x}{1-2a\cos x+a^2}dx?$$

I want to find a complex function and integrate by the residue theorem.

• Are you interested in alternative solutions that don't use complex variables? – David H Jun 6 '14 at 3:59

Since it hasn't been specifically objected to yet, here is a solution that doesn't rely on complex variable methods.

We shall make use of the Fourier sine series,

$$\frac{a\sin x}{1-2a\cos x+a^2}=\begin{cases} \sum_{n=1}^{\infty}a^{n}\sin{(nx)},~~~\text{for }|a|<1,\\ \sum_{n=1}^{\infty}\frac{\sin{(nx)}}{a^{n}},~~~\text{for }|a|>1. \end{cases}$$

These series may readily be derived by taking the imaginary parts of the complex geometric series $\sum_{n=1}^{\infty}\left(ae^{ix}\right)^n$ and $\sum_{n=1}^{\infty}\left(\frac{1}{a}e^{ix}\right)^n$, respectively.

By expanding the integrand in terms of these series and then swapping the order of integration and summation, a closed form may be obtained. For the $|a|>1$ case,

\begin{align}I(a)&=\int_0^\pi \frac{x\sin x}{1-2a\cos x+a^2}\mathrm{d}x\\ &=\int_{0}^{\pi}x\sum_{n=1}^{\infty}\frac{\sin{(nx)}}{a^{n+1}}\mathrm{d}x\\ &=\sum_{n=1}^{\infty}\frac{1}{a^{n+1}}\int_{0}^{\pi}x\sin{(nx)}\mathrm{d}x\\ &=\sum_{n=1}^{\infty}\frac{1}{a^{n+1}}\left(\frac{\sin{(n\pi)}}{n^2}-\frac{\pi\cos{(n\pi)}}{n}\right)\\ &=\pi\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n\,a^{n+1}}\\ &=\frac{\pi}{a}\log{\frac{1+a}{a}}. \end{align}

For the $0<|a|<1$ cases, we can make use of the fact that if $0<|a|<1$, then $\frac{1}{|a|}>1$, thus allowing us to invoke the previous result. Hence,

\begin{align}I(a)&=\int_0^\pi \frac{x\sin x}{1-2a\cos x+a^2}\mathrm{d}x\\ &=\frac{1}{a^2}\int_0^\pi \frac{x\sin x}{a^{-2}-2a^{-1}\cos x+1}\mathrm{d}x\\ &=\frac{1}{a^2}\frac{\pi}{a^{-1}}\log{\frac{1+a^{-1}}{a^{-1}}}\\ &=\frac{\pi}{a}\log{(1+a)}. \end{align}

• Comparing your result with Random Variable's solution, there seems to be a mistake in the argument of $\log$. – Fabian Jun 6 '14 at 4:52
• @Fabian David H's answer is for when $a>1$. Nice answer, BTW. +1 – Random Variable Jun 6 '14 at 4:55
• @RandomVariable Thanks for clarifying. I should have specified the condition on $a$. – David H Jun 6 '14 at 4:59
• Very nice solution! (+1) I am interested in knowing how you came up with that series or where can I find similar ones. Thanks! – Pranav Arora Jun 6 '14 at 6:23
• @PranavArora Random Variable's answer is for the $0<a<1$ case. Mine is for the $1<a$ case. The answers are supposed to be different. ;) – David H Jun 6 '14 at 7:31

I'll first consider the case $0<a<1$.

Let $\displaystyle f(z) = \frac{z}{a-e^{-iz}}$ and integrate around a rectangle with vertices at $\pm \pi$ and $\pm \pi + iR$.

The function $f(z)$ has poles where $a-e^{-iz}=e^{\ln a + 2 \pi i n}-e^{-iz}= 0$.

That is, when $z= i \ln a - 2 \pi n$.

If $0<a< 1$, all of those points are in the lower half-plane.

Letting $R \to \infty$ and going counterclockwise around the contour,

$$\int_{- \pi}^{0} \frac{z}{a-e^{-ix}} \ dx + \int_{0}^{\pi} \frac{x}{a-e^{-ix}} \ dx + i \int_{0}^{\infty}f(\pi + i t) \ dt + \lim_{R \to \infty} \int_{-\pi}^{\pi} f(t + iR) \ dt$$

$$+ \ i \int_{\infty}^{0} f(-\pi+it) \ dy =0$$

Combing the first two integrals,

\begin{align} \int_{- \pi}^{0} \frac{x}{a-e^{-ix}} \ dx + \int_{0}^{\pi} \frac{x}{a-e^{-ix}} \ dx &= -\int_{0}^{\pi} \frac{u}{a-e^{iu}} \ du + \int_{0}^{\pi} \frac{x}{a-e^{-ix}} \ dx \\ &= \int_{0}^{\pi} \frac{-x(a-e^{-ix})+ x(a-e^{ix}) }{(a-e^{ix})(a-e^{-ix})} \ dx \\ &= - 2 i \int_{0}^{\pi} \frac{x \sin x}{1-2a \cos x +a^{2}} \ dx \end{align}

Combining the third and fifth integrals,

\begin{align} i \int_{0}^{\infty} f(\pi + it) \ dt - i \int_{0}^{\infty} f(-\pi + it) \ dt &= i \int_{0}^{\infty} \frac{\pi + it}{a-e^{-i(\pi + it)}} \ dt - i \int_{0}^{\infty} \frac{- \pi + it}{a-e^{-i( -\pi + it)}} \ dy \\ &= i \int_{0}^{\infty} \frac{\pi + it}{a +e^{t}} \ dt - i \int_{0}^{\infty} \frac{- \pi + it}{a+ e^{t}} \ dt \\ &= 2 \pi i \int_{0}^{\infty} \frac{1}{a+e^{t}} \ dt \\ &= 2 \pi i \int_{0}^{\infty} \frac{e^{-t}}{1+ae^{-t}} \ dt \\ &= - \frac{2 \pi i}{a} \ln (1+ae^{-t}) \Big|^{\infty}_{0} \\ &= \frac{2 \pi i}{a} \ln(1+a) \end{align}

And the fourth integral vanishes.

So we have

$$- 2i \int_{0}^{\pi} \frac{x \sin x}{1-2a \cos x +a^{2}} \ dx + \frac{2 \pi i}{a} \ln(1+a) = 0$$

or

$$\int_{0}^{\pi } \frac{x \sin x}{1-2a \cos x +a^{2}} \ dx = \frac{\pi \ln (1+a)}{a}$$

The case for when $a >1$ is similar.

The only difference is that there is now a pole inside of the contour at $z=i \ln a$ with residue $\displaystyle \frac{\ln a}{a}$.

And therefore,

$$- 2i \int_{0}^{\pi} \frac{x \sin x}{1-2a \cos x +a^{2}} \ dx + \frac{2 \pi i}{a} \ln(1+a) = 2 \pi i \frac{\ln a}{a}$$

or

$$\int_{0}^{\pi} \frac{x \sin x}{1-2a \cos x+a^{2}} \ dx = \frac{\pi \ln (1+a)}{a} - \frac{\pi \ln a}{a} = \frac{\pi \ln \left(\frac{1+a}{a} \right)}{a}$$

• I tried to answer this question by considering this integral. If I differentiate it with respect to $n$ and taking $b=1$, I get the same integral as this question but why the result in RHS is not similar with yours nor David's answer? – Tunk-Fey Jun 6 '14 at 12:56
• After Differentiating both sides with respect to $n$, I got $$\int_0^\pi\frac{x\sin nx}{a^2-2ab\cos x+b^2}\, dx=\left\{ \begin{array}{l l} \left(\frac{a}{b}\right)^{n}\cfrac{\pi}{a^2-b^2}\ln\left(\frac{a}{b}\right) &; \quad \text{if }0<a<b,\\ \\ \left(\frac{b}{a}\right)^{n}\cfrac{\pi}{b^2-a^2}\ln\left(\frac{b}{a}\right) &; \quad \text{if }0<b<a. \end{array} \right.$$ But it's not equal to your answer. Do you know why? – Tunk-Fey Jun 6 '14 at 13:05
• @Tunk-Fey In that other problem $n$ is an integer, not a real number. And all of the answers treat $n$ as an integer. So you can't differentiate with respect to $n$. – Random Variable Jun 6 '14 at 13:56
• Ohh, I didn't know that fact. Thanks for pointing it out. +1 for your answer. – Tunk-Fey Jun 6 '14 at 15:25
• @Tunk-Fey Thanks. Checking with Wolfram Alpha, the answer to the other integral is only valid if $n$ is a positive integer. – Random Variable Jun 6 '14 at 16:12


\begin{align}&\color{#c00000}{\int_{0}^{\pi} {x\sin\pars{x} \over 1-2a\cos\pars{x} + a^{2}}\,\dd x} =\half\int_{-\pi}^{\pi}{x\sin\pars{x} \over \pars{a - \expo{\ic x}}\pars{a - \expo{-\ic x}}}\,\dd x \\[3mm]&=\half\int_{-\pi}^{\pi}{x\sin\pars{x} \over 2\ic\sin\pars{x}} \,\pars{{1 \over a - \expo{\ic x}} -{1 \over a - \expo{-\ic x}}}\,\dd x =\half\,\Im\int_{-\pi}^{\pi}{x \over a - \expo{\ic x}}\,\dd x \\[3mm]&=\half\Im \int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} {-\ic\ln\pars{z} \over a - z}\,{\dd z \over \ic z} \\[3mm]&={1 \over 2a}\,\Im\bracks{% \int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} {\ln\pars{z} \over z - a}\,\dd z\ -\ \overbrace{% \int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} {\ln\pars{z} \over z}\,\dd z}^{\ds{=\ 0}}} \end{align}

$$\color{#c00000}{\int_{0}^{\pi} {x\sin\pars{x} \over 1-2a\cos\pars{x} + a^{2}}\,\dd x} ={1 \over 2a}\,\Im \int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} {\ln\pars{z} \over z - a}\,\dd z$$

\begin{align}&\color{#c00000}{\int_{0}^{\pi} {x\sin\pars{x} \over 1-2a\cos\pars{x} + a^{2}}\,\dd x} \\[3mm]&={1 \over 2a}\Im\bracks{% 2\pi\ic\ln\pars{a}\Theta\pars{1 - a} -\int_{-1}^{0}{\ln\pars{-x} + \ic\pi \over x - a}\,\dd x -\int_{0}^{-1}{\ln\pars{-x} - \ic\pi \over x - a}\,\dd x} \\[3mm]&={\pi \over a}\bracks{\ln\pars{a}\Theta\pars{1 - a} -\int_{-1}^{0}{\dd x \over x - a}} ={\pi \over a}\bracks{\ln\pars{a}\Theta\pars{1 - a} + \ln\pars{1 + a \over a}} \end{align}

$$\color{#66f}{\large% \left.\int_{0}^{\pi}{x\sin\pars{x}\,\dd x \over 1-2a\cos\pars{x} + a^{2}} \right\vert_{\ds{\color{#c00000}{\,a > 0}}}} =\color{#66f}{\large% \left\lbrace\begin{array}{lcrcl} {\pi \over a}\,\ln\pars{1 + a} & \mbox{if} & a & < & 1 \\[3mm] {\pi \over a}\,\ln\pars{1 + a \over a} & \mbox{if} & a & > & 1 \end{array}\right.}$$