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
 A: Let's start with the factorization question.  The given integrand is a fraction, and to use the residue theorem, we must find the roots of the denominator, i.e., the roots of 
$$
(2i+1)z^2+6iz+(2i-1).
$$
To find the roots of this polynomial, it's easiest to use the quadratic formula to get that the roots are
\begin{align*}
\frac{-6i\pm\sqrt{(6i)^2-4(2i+1)(2i-1)}}{2(2i+1)}&=\frac{-6i\pm\sqrt{-36+20}}{4i+2}\\
&=\frac{-6i\pm\sqrt{(6i)^2-4(2i+1)(2i-1)}}{2(2i+1)}\\
&=\frac{-6i\pm\sqrt{-16}}{4i+2}\\
&=\frac{-6i\pm4i}{4i+2}
\end{align*}
Therefore, the roots are $\frac{-2i}{4i+2}=\frac{-i}{2i+1}$ and $\frac{-5i}{2i+1}$.  Multiplying through by the conjugate of the denominator, $(1-2i)$ gives that the roots are $\left(-\frac{2}{5}-\frac{1}{5}i\right)$ and $(-2-i)$.
As the OP observes, the polynomial
$$
\left(z-\left(-\frac{2}{5}-\frac{1}{5}i\right)\right)(z-(-2-i))=z^2+\left(\frac{12}{5}+\frac{6}{5}i\right)z+\left(\frac{3}{5}+\frac{4}{5}i\right)
$$
is not the original denominator.  This is another polynomial with the same roots, as the original polynomial.  To make the polynomials the same, we should multiply by $(1+2i)$ to correct the coefficient of $z^2$.  In fact
$$
(1+2i)\left(z^2+\left(\frac{12}{5}+\frac{6}{5}i\right)z+\left(\frac{3}{5}+\frac{4}{5}i\right)\right)=(2i+1)z^2+6iz+(2i-1),
$$
the original polynomial.
Therefore, the original polynomial factors as
$$
(2i+1)z^2+6iz+(2i-1)=(2i+1)\left(z-\left(-\frac{2}{5}-\frac{1}{5}i\right)\right)(z-(-2-i)).
$$
To deal with the residues, the OP correctly determines that $-2-i$ is outside the unit circle, so it doesn't matter for the integral (although it could be used to calculate the integral, but that is a story for another time).
Therefore, the value of the given integral is $2\pi i$ times the residue at $\left(-\frac{2}{5}-\frac{1}{5}i\right)$.  Rewriting the integral as
$$
\int_\gamma \frac{2}{(1+2i)(z-(-2-i))}\cdot\frac{1}{z-\left(-\frac{2}{5}-\frac{1}{5}i\right)}dz,
$$
the value of the residue can be calculated by substituting $\left(-\frac{2}{5}-\frac{1}{5}i\right)$ for $z$ in $\frac{2}{(1+2i)(z-(-2-i))}$.  This substitution results in $-\frac{1}{2}i$ and Cauchy's residue theorem gives that the integral is $\pi$.
The only mistake that the OP seems to make throughout is forgetting the factor of $(1+2i)$ when factoring the denominator.  When that is included, all of the answers (and the limit approach in the question) agree.
A: 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}}$$
