Compute the trigonometric integrals 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.

Here's a way to find $I_n$ with the residue theorem: first, by symmetry, $I_n = \frac{1}{2} \int_0^{2\pi} \frac{1 - \cos(nx)}{1- \cos(x)}dx$.  Consider $z = e^{ix}$ such that the integral with now be on the edge of the unit circle $C$, and use the fact that $$\cos(nx) = \frac{e^{inx} + e^{-inx}}{2}.$$ as well as $\frac{dz}{dx} = i e^{ix}$.  So $dx = \frac{1}{iz} dz$ and
$$\int_0^{2\pi} \frac{1 - \cos(nx)}{1 - \cos(x)} dx = \int_C \frac{1}{iz} \frac{1 - \frac{1}{2}(z^{n} + z^{-n})}{1 - \frac{1}{2}(z + z^{-1})}dz$$ $$= \frac{1}{i}\int_C \frac{1}{z^{n}} \left(\frac{z^n - 1}{z - 1}\right)^2 dz$$ $$= \frac{2\pi i}{i} \mathrm{Res}_{z = 0} \frac{1}{z^{n}} (1 + ... + z^{n-1})^2 = 2\pi n$$
and so $I_n = \pi n$.
