Evaluating $\int_0^{\pi}\frac{\cos n\eta\,d\eta}{1+a^2+2a\cos m\eta}$ The following integral arises in a problem in elasticity
\begin{equation*}
\int_0^{\pi}\frac{\cos n\eta\,d\eta}{1+a^2+2a\cos m\eta}
\end{equation*}
where $m$ and $n$ are both positive integers, and $0<a\le 1/(m-1)$. Mathematica can do this for special choices of $m$ and $n$, but I want a general result for arbitrary $a>0$, $m$ and $n$.
A similar but simpler problem is stated and answered at
Using residues to evaluate the integral $\int_{-\pi}^{\pi} \frac{\cos(n\theta)}{1-2a\cos(\theta)+a^2}d\theta$, $|a|<1$
 A: Using techniques used in the linked question, we can show that
$$\begin{align}I=\int_{0}^{\pi}d\theta\frac{\cos n\theta}{1+a^2+2a\cos m\theta}&=\frac{1}{2}\int_{-\pi}^{\pi}d\theta\frac{\cos n\theta}{1+a^2+2a\cos m\theta}\\&=\frac{1}{2ia}\int_{|z|=1}dz\frac{z^{m+n-1}}{(z^m+a)(z^m+\frac{1}{a})}\end{align}$$
The latter integral is amenable to residue techniques. Assume $0\leq a <1$. Then only the poles attributed to $z^m+a$ are located within the unit circle and contribute to the sum. The poles occur at:
$$z_k=a^{1/m}e^{i\pi/m}e^{\frac{2k\pi i}{m}}$$
Performing the simple residue computation we obtain $(\omega=e^{2\pi i/m}$)
$$I=\sum_{k=0}^{m-1}\frac{z^{m+n-1}}{(z^m+a)'(z^m+\frac{1}{a})}\Bigg|_{z=z_k}=\frac{\pi}{m(1-a^2)}(ae^{i\pi})^{n/m}\sum_{k=0}^{m-1}\omega^{nk}$$
However we note that 
$$\sum_{k=0}^{m-1}(\omega^n)^k=\frac{\omega^{mn}-1}{\omega^n-1}=\begin{Bmatrix}m& ,m|n\\0&, \text{else}\end{Bmatrix}$$
and thus, denoting $d=\frac{n}{m}\in\mathbb{N}$, we finally conclude
$$I=(-1)^d\frac{\pi a^d}{1-a^2}\delta_{n,md}$$
