I’m trying to calculate the following integral: $$I=\int_{0}^{2\pi}\left(\frac{1} {3-2\cos x +\sin x}\right)\,dx$$
Using De Moivre formula, and setting $z= e^{ix}$, the -factorised- integral becomes : $$I=\int{ \frac{2dz} { (z-(2-i)) \cdot (z-\frac{(2-i)}{5}) } }$$ where $|z|=1$ is the contour.
Thefore, using the Residue formula over the closed contour $|z|=1$ gives us: $$I = 2i\pi \cdot \operatorname{Res}\left(f(z),\frac{(2-i)}{5}\right)$$ excluding the other point $2-i$ since it’s out of $|z|=1$.
Calculating the residue, we get $\operatorname{Res}= -1 - \frac{i}{2}$
Thereby, $I = 2i\pi(-1-\frac{i}{2}) = \pi - 2i\pi$.
The thing is that the result of the integral can’t have an imaginary part since the main integral is all real...
Doing a further search I got to find that the integral equals: $I = \pi$ , which is the real part of my answer.
So what did I do wrong? Where’s my mistake?
Let $f$ be on $\left[0,2\pi\right]$ $$ f\left(x\right)=\frac{1}{3-2\cos(x)+\sin(x)} $$ With $z=e^{ix}$ we have $\text{d}z=iz\text{d}x$ and $\displaystyle \frac{z+z^{-1}}{2}=\cos(x)$ and $\displaystyle \frac{z-z^{-1}}{2}=\sin(x)$ Hence $$ f\left(x\right)=\frac{2}{6-2z-2z^{-1}-iz+iz^{-1}}=\frac{2}{6-\left(2+i\right)z-\left(2-i\right)z^{-1}}=\frac{2z}{6z-\left(2+i\right)z^2-\left(2-i\right)}$$ So we got slicely what you've done ( careful with the coefficient next time ) because if $P(x)=ax^2+bx+c$ with $x_1$ and $x_2$ two roots then $$ P\left(x\right)=a\left(x-x_1\right)\left(x-x_2\right) $$ here you forgot the $a=2+i$.
Now dont forget that you did a change of variable in an integrable, dont forget the $\text{d}z$ hence $$ \int_{0}^{2\pi}f\left(x\right)\text{d}x=\int_{\mathscr{C}}^{ }\frac{f\left(z\right)}{iz}\text{d}z=\int_{\mathscr{C}}^{ }\frac{-2i\text{d}z}{6z-\left(2+i\right)z^2-\left(2-i\right)} $$
As you said, only one root interests us, and miraculously
$$\text{Res}\left(f,\frac{2}{5}-\frac{i}{5}\right)=-\frac{i}{2} $$ And finally
Hope it helped you