Solving integral using residues I'm trying to find the value of the integral $\int_0^{2\pi}\frac{\cos^2u}{2-\sin u}du$ using the substitution: $\cos u =\frac{1}{2}(z+\frac{1}{z})$ and $\sin u = \frac{1}{2i}(z-\frac{1}{z})$. Making the substitution, we obtain $\int_C(z^2+1)^2/(2z^2(z^2+4iz-1)dz$ where C denotes the unit circle. I leave out the steps inbetween because I do not believe the error was made there.
Next, I found the roots of the polynomial in the denominator, which are the poles of the integrand. I found these to be $z_0=0$, $z_1=i(-2+\sqrt3)$, $z_2=i(-2-\sqrt3)$. Only $z_0$ and $z_1$ lie inside the unit circle, so the value of the integral will be $2\pi i[Res(0)+Res(i(-2+\sqrt3))]$. $Res(0)$ is easily obtained. $Res(i(2-\sqrt3))$ should be too, since $z_1$ is a first order pole, so I can just take $lim_{z\to z_1}[f(z)(z-z_1)]$. The results are $$Res(0)= lim_{z\to 0}\frac{d}{dz}z^2f(z)=...=-2i$$ and $$Res(i(\sqrt3-2))=lim_{z\to z_1}(z-z_1)f(z)=...=-3/2+\sqrt3$$
What mistake did I make? My answer turns out to be $2\pi i(-2i-3/2+\sqrt3)$, the solution is $-2\pi(\sqrt3-2)$.

Let $\tan\frac{u}{2}=x$.
Thus, $$dx=\frac{1}{2\cos^2\frac{u}{2}}du=\frac{1}{2}(1+x^2)du,$$ which gives
$$du=\frac{2}{1+x^2}dx.$$
Hence, $$\int\frac{\cos^2u}{2-\sin{u}}du=\int\left(2+\sin{u}-\frac{3}{2-\sin{u}}\right)du=$$
$$=2u-\cos{u}-3\int\frac{1}{2-\frac{2x}{1+x^2}}\frac{2}{1+x^2}dx=$$
$$=2u-\cos{u}-3\int\frac{1}{1-x+x^2}dx=2u-\cos{u}-3\int\frac{1}{\left(x-\frac{1}{2}\right)^2+\left(\frac{\sqrt3}{2}\right)^2}dx=$$
$$=2u-\cos{u}-2\sqrt3\arctan\frac{2\tan\frac{u}{2}-1}{\sqrt3}+C.$$
Can you end it now?
