TITLE: Compute the trigonometric integrals
QUESTION [7 upvotes]: How would you compute the following integrals?
$$ I_{n} = \int_0^\pi \frac{1-\cos nx}{1- \cos x} dx  $$
$$ J_{n,m} = \int_0^\pi \frac{x^m(1-\cos nx)}{1- \cos x} dx  $$
For instance, i noticed that the first integral is convergent for any value of $n$ since $\lim_{x\to0} \frac{1- \cos nx}{1 - \cos x}= n^2$. This fact may also be extended to the second integral, as well.

REPLY [3 votes]: Another generating function approach is to set $z=e^{ix}$ in
$$
\begin{align}
&\sum_{k=0}^\infty\frac{(it)^m}{m!}\int_0^{\pi}x^m\frac{1-\cos(nx)}{1-\cos(x)}\,\mathrm{d}x\\
&=\int_0^{\pi}z^t\left(\frac{z^n-1}{z-1}\right)^2\frac{\mathrm{d}z}{iz^n}\\
&=\frac1i\int_0^{\pi}\left(\sum_{k=1-n}^{n-1}(n-|k|)z^{k+t-1}\right)\mathrm{d}z\\
&=\frac1i\sum_{k=1-n}^{n-1}(n-|k|)\frac{(-1)^ke^{\pi it}-1}{k+t}\\
&=in\frac{1-e^{\pi it}}{t}-2it\sum_{k=1}^{n-1}\frac{n-k}{k^2-t^2}\left(1-(-1)^ke^{\pi it}\right)\tag{1}
\end{align}
$$
As $t\to0$, it is easy to see that we get $\pi n$.