I have an integral to solve using appropriate contour integrals; The question is like this. $$\int\limits_0^{2\pi}\frac{\cos(n\theta)d\theta}{1+2p\cos(\theta)+p^2}$$ $$-1<p<1$$
So I thought about starting this assigning $\theta$ to $z$ by defining a new function. $$f(z)=\frac{\cos(nz)d\theta}{1+2p\cos(\theta)+p^2} = \frac{e^{inz}d\theta}{1+2pe^{iz}+p^2}$$ But when I tried to find the poles in the $f(z)$, I got stuck a little. If $p$ is $1$ then when $\cos(\theta)$ is $-1$ we have a pole. Same way if $p$ is $-1$, then at $\cos(\theta) = 1$ we have a pole. But $p$ cannot reach $-1$ and $1$. How can I get the poles in this function? :)
Try the substitution: $$ z=e^{i\theta}\implies dz=izd\theta\\ 2\cos\theta= z+{1\over z}\\ \implies 2\cos n\theta=z^n+{1\over z^n} $$ and consider the counter-clockwise contour $|z|=1$. Your integral becomes $$ {1\over2ip}\oint_{|z|=1}{z^{2n}+1\over z^{n}(z+{1\over p})(z+p)}dz $$ With $0<|p|<1$, your poles are: $-p$ with order $1$, $0$ with order $n$. For $a\neq0$ we have $$ {d^{n-1}\over dz^{n-1}}{z^{2n}\over z+a}\Big{|}_{z=0}=\sum_{j=0}^{n-1}\binom{n-1}{j}\underbrace{{d^jz^{2n}\over dz^{j}}\Big{|}_{z=0}}_{=0}{d^{n-1-j}\over dz^{n-1-j}}{1\over(z+a)}\Big{|}_{z=0}=0\\ {d^{n-1}\over dz^{n-1}}{z^{2n}+1\over (z+{1\over p})(z+p)}\Big{|}_{z=0}={1\over{1\over p}-p}{d^{n-1}\over dz^{n-1}}\left[(z^{2n}+1)\left({1\over z+p}-{1\over z+{1\over p}}\right)\right]\Big{|}_{z=0}=\\ {p\over1-p^2}{d^{n-1}\over dz^{n-1}}\left[{1\over z+p}-{1\over z+{1\over p}}\right]\Big{|}_{z=0}={p\over1-p^2}\left[{(-1)^{n-1}(n-1)!\over(z+p)^{n}}-{(-1)^{n-1}(n-1)!\over(z+{1\over p})^{n}}\right]\Big{|}_{z=0}=\\ {p\over p^2-1}(-1)^n(n-1)!\left[{1\over p^{n}}-p^{n}\right] $$ So residue at $0$ is $$(-1)^n{p-p^{2n+1}\over p^{n}(p^2-1)}$$ Residue at $-p$ is $$ -(-1)^n{p^{2n}+1\over p^{n-1}(p^2-1)} $$ Finally, your integral is $$(-1)^n{2\pi p^n\over1-p^2}$$