Need help proving this integration If $a>b>0$, prove that :

$$\int_0^{2\pi} \frac{\sin^2\theta}{a+b\cos\theta}\ d\theta = \frac{2\pi}{b^2} \left(a-\sqrt{a^2-b^2} \right) $$

 A: $$I = \int_0^{2 \pi} \dfrac{\sin^2(x)}{a+b \cos(x)} dx \implies aI = \int_0^{2 \pi} \dfrac{\sin^2(x)}{1+\dfrac{b \cos(x)}a}dx$$
\begin{align}
aI & = \sum_{k=0}^{\infty}\left(\dfrac{(-b)^k}{a^k} \int_0^{2 \pi}\sin^2(x) \cos^k(x) dx \right) = \sum_{k=0}^{\infty}\left(\dfrac{b^{2k}}{a^{2k}} \int_0^{2 \pi}\sin^2(x) \cos^{2k}(x) dx \right)
\end{align}
Note that we have thrown away the odd terms since for $k$ odd, the integral $\displaystyle \int_0^{2 \pi}\sin^2(x) \cos^k(x) dx$ is zero.
\begin{align}
\dfrac{\displaystyle \int_0^{2 \pi}\sin^2(x) \cos^{2k}(x) dx}4 & = \int_0^{\pi/2}\sin^2(x) \cos^{2k}(x) dx\\
& 
\int_0^{\pi/2}\cos^{2k}(x) dx - \int_0^{\pi/2}\cos^{2k+2}(x) dx\\
& = \dfrac{2k-1}{2k} \dfrac{2k-3}{2k-2} \cdots \dfrac12 \dfrac{\pi}2 - \dfrac{2k+1}{2k+2} \dfrac{2k-1}{2k} \dfrac{2k-3}{2k-2} \cdots \dfrac12 \dfrac{\pi}2\\
& = \dfrac1{2k+2} \dfrac{2k-1}{2k} \dfrac{2k-3}{2k-2} \cdots \dfrac12 \dfrac{\pi}2\\
& = \dfrac{\pi}{2^{k+2}} \dfrac{(2k-1)(2k-3)\cdots3 \cdot 1}{(k+1)!} = \dfrac{\pi}{2^{2k+2}} \dfrac{(2k)!}{k! (k+1)!}
\end{align}
Hence,
$$\dfrac{aI}{\pi} = \sum_{k=0}^{\infty} \left(\dfrac{b}{2a} \right)^{2k} \underbrace{\dfrac{(2k)!}{k! (k+1)!}}_{\text{Catalan numbers}}$$
Now $$\sum_{k=0}^{\infty} \dfrac{\dbinom{2k}k x^{k}}{k+1} = \dfrac{1-\sqrt{1-4x}}{2x} \,\,\,\,\,\, \forall \vert x \vert < \dfrac14$$ This is the generating function for the Catalan numbers. Hence, in our case, we get that
$$\sum_{k=0}^{\infty} \left(\dfrac{b}{2a} \right)^{2k} \underbrace{\dfrac{(2k)!}{k! (k+1)!}}_{\text{Catalan numbers}} = \dfrac{1-\sqrt{1-4 \cdot \left(\dfrac{b}{2a} \right)^2}}{2 \cdot \left(\dfrac{b}{2a} \right)^2} \,\,\,\,\,\,\,\,\forall \dfrac{b}{2a} < \dfrac12$$
Hence,
$$\dfrac{aI}{\pi} = \dfrac{1-\sqrt{1-\left(\dfrac{b}a\right)^2}}{\dfrac{b^2}{2a^2}} = \dfrac{a-\sqrt{a^2-b^2}}{\dfrac{b^2}{2a}}$$
Hence,
$$I = \dfrac{2\pi}{b^2} (a-\sqrt{a^2-b^2})$$
A: You can solve it with direct integration some subsitutions gives you  the antiderivative: 
$$\frac{-2 \sqrt{b^2-a^2} \tanh ^{-1}\left(\frac{(a-b) \tan \left(\frac{\theta }{2}\right)}{\sqrt{b^2-a^2}}\right)+a \theta -b \sin (\theta )}{b^2}$$
use a substituion like 
$t=\tan(\theta)$. (and a lot of the trigonometric identies.)
We use the identies 
\begin{align*}
\cos(\arctan(t))&=\frac{1}{\sqrt{1+t^2}}\\
\sin(\arctan(t))&=\frac{t}{\sqrt{1+t^2}}
\end{align*}
So we have 
$$\int \frac{\sin^2(\theta)}{a+b\cos(\theta)}\, \mathrm{d}\theta= \int 
\frac{t^2}{a + b \frac{1}{\sqrt{1+t^2}}} \, \mathrm{d} t$$
With residue theorem it should work like this :
$$\int_0^{2\pi} \frac{\sin^2(\theta)}{a+ b \cos(\theta)}\, \mathrm{d}\theta=
-\int_0^{2\pi} \frac{1}{4}\cdot \frac{(\exp(i \theta)- \exp(-i \theta))^2}{a+\frac{b}{2} (\exp(i\theta) +\exp(-i\theta)} \, \mathrm{d}\theta$$
Chosing the way $\gamma(\theta) = e^{i\theta}$we see that it equal
$$-\frac{1}{4i} \int_\gamma \frac{(z-z^{-1})^2}{a+ \frac{b}{2} (z+z^{-1})} \cdot \frac{1}{z} \, \mathrm{d} z$$
Expanding gives us 
$$-\frac{1}{4i} \int_\gamma \frac{z^2 -2 + \frac{1}{z^2}}{a+ \frac{b}{2} (z+\frac{1}{z})} \cdot \frac{1}{z} \, \mathrm{d}z=-\frac{1}{4i} \int_\gamma \frac{z^2 -2 + \frac{1}{z^2}}{za+ \frac{b}{2} (z^2+1)}  \, \mathrm{d}z$$
A: First step: $\cos(\theta+\pi)=-\cos(\theta)$ and $\sin^2(\theta+\pi)=\sin^2(\theta)$ hence the integral $I$ to be computed is
$$
I=\int_0^\pi\frac{\sin^2\theta}{a+b\cos\theta}\mathrm d\theta+\int_0^\pi\frac{\sin^2\theta}{a-b\cos\theta}\mathrm d\theta=2aJ,
$$
with
$$
J=\int_0^\pi\frac{\sin^2\theta}{a^2-b^2\cos^2\theta}\mathrm d\theta.
$$
Second step: the transformation $\theta\to\theta+\pi$ leaves the integrand unchanged hence one uses the change of variable $t=\tan\theta$, $\mathrm dt=(1+t^2)\mathrm d\theta$, which yields
$$
J=\int_{-\infty}^{+\infty}\frac{t^2}{a^2(1+t^2)-b^2}\frac{\mathrm dt}{1+t^2}.
$$
Third step: the fraction with argument $t^2$ can be decomposed as
$$
\frac{x}{(a^2(1+x)-b^2)(1+x)}=\frac1{b^2}\left(\frac{1}{1+x}-\frac{a^2-b^2}{a^2(1+x)-b^2}\right),
$$
hence
$b^2J=K-(a^2-b^2)L$ with
$$
K=\int_{-\infty}^{+\infty}\frac{\mathrm dt}{1+t^2},\qquad L=\int_{-\infty}^{+\infty}\frac{\mathrm dt}{a^2t^2+a^2-b^2}.
$$
Fourth step:  the change of variable $at=\sqrt{a^2-b^2}s$ yields
$$
L=\frac{\sqrt{a^2-b^2}}a\int_{-\infty}^{+\infty}\frac{\mathrm ds}{(a^2-b^2)(1+s^2)}=\frac{K}{a\sqrt{a^2-b^2}},
$$
and the integral $K$ is classical, its value is $K=\pi$.
Conclusion:
$$
I=2aJ=\frac{2a}{b^2}\left(K-(a^2-b^2)\frac{K}{a\sqrt{a^2-b^2}}\right)=\frac{2\pi}{b^2}\left(a-\sqrt{a^2-b^2}\right)
$$
A: I'll do this one $$\int_{0}^{2\pi}\frac{cos(2\theta)}{a+bcos(\theta)}d\theta$$if we know how to do tis one you can replace $sin^{2}(\theta)$ by $\frac{1}{2}(1-cos(2\theta))$ and do the same thing.  if we ae on the unit circle we know that $cos(\theta)=\frac{e^{i\theta}+e^{-i\theta}}{2}$ so by letting $z=e^{i\theta}$ we wil get$$cos(\theta)=\frac{z+\frac{1}{z}}{2}=\frac{z^2+1}{2z}$$and$$cos(2\theta)=\frac{z^2+\frac{1}{z^2}}{2}=\frac{z^4+1}{2z^2}$$ thus, if$\gamma: |z|=1$ the integral becomes $$\int_{\gamma}\frac{\frac{z^4+1}{2z^2}}{a+b\frac{z^2+1}{2z}}\frac{1}{iz}dz=\int_{\gamma}\frac{-i(z^4+1)}{2z^2(bz^2+2az+b)}dz$$now the roots of $bz^2+2az+b$ are $z=\frac{-2a\pm \sqrt{4a^2-4b^2}}{2b}=\frac{-a}{b}\pm\frac{\sqrt{a^2-b^2}}{b}$, you can check that the only root inside $|z|=1$ is $z_1=\frac{-a}{b}+\frac{\sqrt{a^2-b^2}}{b}$ so the only singularities of the function that we want to integrate inside $\gamma$ are $z_0=0$ and $z_1$ both are poles. find the resudies and sum them to get the answer.Notice that this will only give youe "half" the answer you still have to do$$\frac{1}{2}\int_{\gamma}\frac{d\theta}{a+bcos(\theta)}$$ in the same way to get the full answer.
