Finding the integral $\int_0^\pi\frac{d\theta}{(2+\cos\theta)^2}$ by complex analysis Trying to find the integral $$\int_0^\pi\frac{d\theta}{(2+\cos\theta)^2}$$ by complex analysis. 
I let $z = \exp(i\theta)$, $dz = i \exp(i\theta)d\theta$, so $ d\theta=\dfrac{dz}{iz}$. I am trying therefore to find the integral $$\frac{1}{2iz} \oint_C \frac{dz}{\left(2 + \frac{z}{2} + \frac{1}{2z}\right)^2}$$ I am unsure of which contour I should use, and how to proceed besides that. Could anyone help? 
 A: First note that
$$\int_0^\pi \frac{d\theta}{(2+\cos \theta)^2} = \frac12 \int_{-\pi}^\pi \frac{d\theta}{(2+\cos \theta)^2}.$$
Then use the same substitution as the one you tried. You get your contour for free. (If $\theta$ varies from $-\pi$ to $\pi$, then $e^{i\theta}$ will cover the unit circle exactly once.)
Finally, clear the fractions, find the poles, and compute the residues for the poles that are inside the unit circle.
A: You first could take a look at an easier Integral to evaluate. Let F(a) be $$\int_{0}^{\pi}\frac{1}{a+\cos\left(x\right)}dx$$ Now, in complex form, this Integral will be $$\int_{0}^{\pi}\frac{1}{a+\frac{e^{ix}+e^{-ix}}{2}}dx$$ $$\int_{0}^{\pi}\frac{1}{a+\frac{e^{ix}+e^{-ix}}{2}}dx=2\int_{0}^{\pi}\frac{1}{2a+e^{ix}+e^{-ix}}dx$$ So after we do the substitution $$z = e^{ix}$$ This integral will be equal to $$\int_{c}^{ }\frac{2}{\left(2a+z+z^{-1}\right)iz}dz=\int_{c}^{ }-\frac{2i}{z^{2}+2az+1}dz$$ after we do some substitution. Now let's evaluate this using complex analysis. Using the quadratic equation, we notice that the pole of this equation will be at $$\sqrt{a^{2}-1}-a$$ (There's also the negative version, but that is outside of the unit circle). Then, now what we need to do is just apply the Residue Theorem (As in this particular expression we don't have major "problems" we need to deal with) $$Res_{z=\sqrt{a^{2}-1}-a}=\frac{-2i}{2\sqrt{a^{2}-1}}$$ Now we just need to multiply the Residue by 2i. So our result for F(a) will be $$\frac{\pi}{\sqrt{a^{2}-1}}$$ After all that, we get $$\int_{0}^{\pi}\frac{1}{a+\cos\left(x\right)}dx = \frac{\pi}{\sqrt{a^{2}-1}}$$ That initially was our function F(a). Now we're going to use a "trick", that is the Leibniz’s rule for differentiation under the sign of integration sign. I'm not going over all of that, but you probably already know it. $$\int_{0}^{\pi}\frac{1}{a+\cos\left(x\right)}dx = \frac{\pi}{\sqrt{a^{2}-1}}$$
Differentiating both sides in terms of a, we get $$-\int_{0}^{\pi}\frac{1}{\left(a+\cos\left(x\right)\right)^{2}}dx = \frac{-a\pi}{\sqrt{\left(a^{2}-1\right)^{3}}}$$ As we have the negative sign in both sides, we can just cancel them. Leaving us with the result $$\int_{0}^{\pi}\frac{1}{\left(a+\cos\left(x\right)\right)^{2}}dx = \frac{a\pi}{\sqrt{\left(a^{2}-1\right)^{3}}}$$
This expression works for all real values in which the magnitude of a is greater than one (if the magnitude of a is equal or less than one, the integral is undefined)
The answer for your original question is $$\int_{0}^{\pi}\frac{1}{\left(2+\cos\left(x\right)\right)^{2}}dx=\frac{2\pi}{\sqrt{27}}$$
Sorry if something was not very well described, I'm not a teacher and that's the first time I write something in StackExchange. And if you felt some lacking in the citations of the techniques I used, you can just google them and it should be very easy to find some paper about it. Thank you, I hope it was helpful to someone in any way.
