In calculus class our teacher demonstrated us the evaluation of the definite integral $\int_0^\pi \dfrac{1}{a+b\cos(x)}dx=\dfrac{\pi}{\sqrt{a^2-b^2}}$, for $a\ne 0, b \ne 0, |\dfrac ba \lt 1|$, but there's a part I could not grasp.
Our teacher started out by setting up an equality: $bz^2+2az+b=b(z-\alpha)(z-\beta)$, where $\alpha, \beta$ are the roots of the expression on the LHS in $\Bbb C$, and $\alpha$ takes on the value with a negative sign before the radical, while $\beta$ is the other one. Letting $z=e^{ix}$, the integrand is transformed into the following form:
$\dfrac{1}{\sqrt{a^2-b^2}}\left(\dfrac{\alpha}{\alpha-e^{ix}}-\dfrac{\beta}{e^{ix}-\beta}\right)=\dfrac{1}{\sqrt{a^2-b^2}}\left(\dfrac{1}{\alpha e^{-ix}-1}+\dfrac{1}{1-\beta e^{-ix}}\right)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=0}^{\infty}(\beta^n-\alpha^n)e^{-inx}=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=1}^{\infty}(\beta^n-\alpha^n)(\cos(nx)-i\sin(nx))$
But then $\int_0^\pi \cos(nx)-i\sin(nx) dx=\dfrac 1n(\sin(nx)+i\cos(nx))|_0^\pi=\dfrac in(\cos(n\pi)-1)$ and I was completely lost on how the next part was carried out. For if we substitute that back into the infinite sum, we get that integrated version of that expression would be $\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=1}^{\infty}(\beta^n-\alpha^n)\dfrac in(\cos(n\pi)-1)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{k=1}^{\infty}(\beta^{2k-1}-\alpha^{2k-1})\dfrac {i}{2k-1}(\cos((2k-1)\pi)-1)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{k=1}^{\infty}(\beta^{2k-1}-\alpha^{2k-1})\dfrac {-2i}{2k-1}$
Yet I fail to see how this could lead to the supposed final result, especially with that $i$ there.