<s>[INST] Factorization of $(1+2i)z^2+6iz+2i-1$ to find the residues, but it doesn't work I'm doing complex analysis and I have the following $$\int_{C}\frac{2dz}{(2i+1)z^2+6iz+2i-1}$$ where $C$ is the unit circle. I tried factorizing this polynomial and find the residues but I really can't solve this.
This is my work:
$$z_{1,2} = \frac{-3i\pm \sqrt{-9-(-4-1)} }{2i+1}=\frac{-3i\pm 2i}{1+2i} \cdot \frac{1-2i}{1-2i}= \frac{-3i-6\pm 2i\pm 4}{5}$$ which gives $z_1 = -\frac{2}{5}-\frac{i}{5}$ and $z_2 = -2-i$. Now clearly $z_2$ is outside the unit circle so I just have to consider the residue of $z_1$.
However I think I'm either making a factorisation mistake or a mistake in the roots. Indeed if we check the roots, I don't get the same polynomial! $$(z+2+i)\left(z+\frac{2}{5}+\frac{i}{5}\right) = z^2 +z\left(\frac{12}{5}+\frac{6i}{5}\right)+\frac{4i}{5}+\frac{3}{5}$$ which is clearly not the same polynomial I started with. Also if I try to calculate the residue using the limit, I don't get the correct one. Where's my mistake?
EDIT
As requested, I'll add some more calculations. To calculate the residue I did the following: $$\lim_{z\to z_1}(z+\frac{2}{5}+\frac{i}{5})\frac{2}{(z+2+i)\left(z+\frac{2}{5}+\frac{i}{5}\right)} = \frac{2}{\frac{8}{5}+\frac{4i}{5}} = \frac{5}{4+2i} = \frac{20-10i}{20}=1-\frac{i}{2}$$ which is clearly wrong as this integral is the mapping of a real integral of the first type (rational function in sine and cosine). Indeed by Cauchy's Residue Theorem this should give that the value of the initial real integral is $2\pi i (1-\frac{i}{2}) = 2\pi i+\pi$ which is a complex value, so this is wrong
 [/INST] If you were only interested in the value of your integral $f$ you could let $z=\exp (i \theta )$ and get
$$fr=\int_0^{2 \pi } \frac{1}{\sin (\theta )+2 \cos (\theta )+3} \, d\theta$$
In order to calculate the integral we attempt to use the fundamental theorem of calculus, i.e. taking the difference of the anitiderivative at both ends of the integration interval. But this holds only for continuous antiderivatives. If the antiderivative contains jumps these must be taken into account.
An antiderivative of the integrand is
$$fa=-\tan ^{-1}\left(\frac{2}{\tan \left(\frac{\theta }{2}\right)+1}\right)$$
In the region of integration the denominator vanishes at $\theta =\frac{3 \pi }{2}$. Here the antiderivative makes a jump from
$$\lim_{\theta \to \left(\frac{3 \pi }{2}\right)^-} \, fa=\frac{\pi }{2}$$
to 
$$\lim_{\theta \to \left(\frac{3 \pi }{2}\right)^+} \, fa=-\frac{\pi }{2}$$
i.e. it jumps by an amount of $\pi$.
Now the antiderivative at both ends of the integration interval is equal to $-\tan ^{-1}(2)$. Hence the difference is zero, and we are left with the jump which gives $f=fr=\pi$.
EDIT
I'm afraid I have made it more complicated than necessary. 
Let us therefore apply a "standard" procedure and do this for the more general integral (displayed here in original form and reduced form)
$$\int_0^{2 \pi } \frac{1}{a+b \cos (\theta )+c \sin (\theta )} \, d\theta =\int_0^{2 \pi } \frac{1}{a+\sqrt{b^2+c^2} \cos (\phi )} \, d\phi =\frac{2 \pi }{\sqrt{a^2-b^2-c^2}}$$
which holds for $a^2-b^2-c^2>0$
Making the "standard" substitution $\theta \to 2 \tan ^{-1}(t)$, $\text{d$\theta $}=\frac{2 \text{dt}}{t^2+1}$ and splitting the integral into the two parts from $0$ to $\pi$ and form $\pi$ to $2 \pi$ gives the complete integration range in to from $-\infty$ to $\infty$.
We have
$$\cos (\theta )=\cos ^2\left(\frac{\theta }{2}\right)-\sin ^2\left(\frac{\theta }{2}\right)=\left(1-t^2\right) \cos ^2\left(\frac{\theta }{2}\right)$$
$$\sin (\theta )=2 \sin \left(\frac{\theta }{2}\right) \cos \left(\frac{\theta }{2}\right)=2 t \cos ^2\left(\frac{\theta }{2}\right)$$
$$\frac{1}{\cos ^2\left(\frac{\theta }{2}\right)}=t^2+1$$
The integral becomes 
$$2 \int_{-\infty }^{\infty } \frac{1}{a \left(t^2+1\right)+b \left(1-t^2\right)+2 c t} \, dt$$
Supplementing the square, shifting the integration varibale (this makes no dfference in our infnte interval) and extracting factors gives finally
$$\frac{\int_{-\infty }^{\infty } \frac{2}{v^2+1} \, dv}{\sqrt{a^2-b^2-c^2}}=\frac{2 \pi }{\sqrt{a^2-b^2-c^2}}$$
</s>