<s>[INST] Evaluating the integral with trigonometric integrand While solving another problem I have come across this integral which I am unable to evaluate. Can someone please evaluate the following integral? Thank you. 

$$\int_0^{2\pi}\frac{1}{(2+\cos\theta)^2}\,d\theta.$$

 [/INST] Here is an ugly way of doing it. Pranav's solution is much more elegant.
First substitute $u = \tan(\tfrac{\theta}{2})$ and $\mathrm{d}u = \tfrac{1}{2} \sec^2(\tfrac{\theta}{2})\mathrm{d}\theta$. Then, transform the integrand using the substitution $\sin(\theta) = \frac{2u}{u^2+1}$, $\cos(\theta) = \frac{1-u^2}{u^2+1}$ and $\mathrm{d}\theta = \frac{2\mathrm{d}u}{u^2+1}$ to get $$I = \int \frac{1}{(2+\cos(\theta))^2}\mathrm{d}\theta = \int \frac{2}{(u^2 + 1)\left(\tfrac{1-u^2}{u^2+1} +2\right)^2} \mathrm{d}u = 2\int \frac{u^2+1}{u^4 + 6u^2 +9} \mathrm{d}u.$$
Now, using partial fractions, one can rewrite this integral as
$$I = \frac{2}{3}\int\frac{1}{\tfrac{u^2}{3}+1}\mathrm{d}u - 4\int\frac{1}{(u^2+3)^2}\mathrm{d}u.$$
For the first integrand, substitute $s = \frac{u}{\sqrt{3}}$ and $\mathrm{d}s = \frac{1}{\sqrt{3}}\mathrm{d}u$ to get
$$I = \frac{2}{\sqrt{3}} \int \frac{1}{s^2+1} \mathrm{d}s - 4\int\frac{1}{(u^2+3)^2}\mathrm{d}u.$$ 
We know how to integrate the left side. This is just
$$I = \frac{2\arctan(s)}{\sqrt{3}} - 4\int\frac{1}{(u^2+3)^2}\mathrm{d}u.$$
For the right-hand side, we substitute $u = \sqrt{3}\tan(p)$ and $\mathrm{d}u=\sqrt{3}\sec^2(p)\mathrm{d}p$. Then, we have that $(u^2+3)^2 = (3\tan^2(p) +2)^2 = 9\sec^4(p)$ and $p = \arctan(\tfrac{u}{\sqrt{3}})$. This yields the integral
$$I = \frac{2\arctan(s)}{\sqrt{3}} - \frac{4}{3\sqrt{3}} \int \cos^2(p) \mathrm{d}p.$$
Integrating $\cos^2(p)$ is easy by using the identity $\cos^2(p) = \frac{\cos(2p) + 1}{2}$. All that remains now is to integrate this and substitute your way back to express $I$ in terms of $\theta$. Evaluate from $0$ to $2\pi$ to obtain
$$I_0^{2\pi} = \frac{4\pi}{3\sqrt{3}}.$$
</s>