Solve integrals using residue theorem? $$\int_{0}^{\pi}\frac{d\theta }{2+\cos\theta}$$
$$\int_{0}^{\infty}\frac{x }{(1+x)^6} dx$$
My problem is that I don't know how to start solving these integrals, or how to convert them into usual types that can be solved.
 A: Hint for the First one First compute 
$$
I=\int_0^{2\pi} \frac{d\theta}{2 + \cos\theta}=\int_0^{2\pi}R(\cos(\theta), \sin(\theta)) d\theta
$$
Where $R$ is the rational function given by $$R(x,y)=\frac{1}{2+x}$$
How to do this using the residue theorem? Put $z=e^{it}=\cos(t)+i\sin(t)$, thus 
$$
\cos(t)=Re(z)=\frac{z+z^{-1}}{2}, \ \\ \sin(t)=Im(z)=\frac{z-z^{-1}}{2i}, \\ dz=ie^{it} dt=iz \ dt \Longrightarrow dt=\frac{1}{iz}dz
$$
Then $I$ can be seen as a contour integral, solve it by using residues 
$$
I=\int_0^{2\pi}R(\cos(t), \sin(t)) dt= \int_{|z|=1} R\left(\frac{z+1/z}{2}, \frac{z-1/z}{2i} \right)\frac{1}{iz}dz
$$
Hence in your case the integral you will compute is
$$
I= \int_{|z|=1} \left(\frac{1}{2+\frac{z+1/z}{2}} \right)\frac{1}{iz}dz = \frac{2}{i} \int_{|z|=1} \frac{dz}{z^2+4z+1}
$$
which can be easily obtain by the residue theorem!
Finally: Note that 
$$
\int_0^{\pi} \frac{d\theta}{2 + \cos\theta}=\frac{I}{2}
$$
and hence your result follows by computing the next integral 
$$
\int_0^{\pi} \frac{d\theta}{2 + \cos\theta} = \frac{1}{i} \int_{|z|=1} \frac{dz}{z^2+4z+1} 
$$ 
Spoiler Solution

 Since $z^2+4z+1=(z-(\sqrt{3}-2))(z-(-\sqrt{3}-2))$ and $z_0=\sqrt{3}-2$ is the only root inside the contour $|z|=1$, then by the residue theorem we have $\displaystyle \int_{|z|=1} \frac{dz}{z^2+4z+1} = 2\pi i \left( \frac{1}{2\sqrt{3}}\right)=i \frac{\pi}{\sqrt{3}}$. Hence we get that the final result is $\displaystyle \int_0^{\pi} \frac{d\theta}{2 + \cos\theta}  =\frac{1}{i} \times i \frac{\pi}{\sqrt{3}}=\frac{\pi}{\sqrt{3}}$

A: For the second integral:
Note first that this integral is easily done by recognizing that $x=(1+x)-1$, so the integral is really
$$\int_0^{\infty} \frac{dx}{(1+x)^5} - \int_0^{\infty} \frac{dx}{(1+x)^6} = \frac14-\frac15=\frac1{20}$$
One may also use the residue theorem.  However, one must choose an appropriate contour and integrand.  In this case, a useful contour integral to consider is
$$\oint_C dz \frac{z \log{z}}{(1+z)^6} $$
where $C$ is a keyhole contour of outer radius $R$ and inner radius $\epsilon$ about the positive real axis.  The contour integral is then equal to
$$\int_{\epsilon}^R dx \frac{x \log{x}}{(1+x)^6} + i R \int_0^{2 \pi} d\theta \, e^{i \theta} \frac{R e^{i \theta} \log{(R e^{i \theta})}}{(1+R e^{i \theta})^6} \\ + \int_R^{\epsilon} dx \frac{x (\log{x}+i 2 \pi)}{(1+x)^6} + i \epsilon \int_{2 \pi}^0 d\phi \, e^{i \phi} \frac{\epsilon e^{i \phi} \log{(\epsilon e^{i \phi})}}{(1+\epsilon e^{i \phi})^6}$$
As $R \to \infty$, the second integral vanishes as $\log{R}/R^4$.  As $\epsilon \to 0$, the fourth integral vanishes as $\epsilon^2 \log{\epsilon}$.  Thus, the contour integral is, in this limit
$$-i 2 \pi \int_0^{\infty} dx \frac{x}{(1+x)^6} $$
By the residue theorem, the contour integral is also equal to $i 2 \pi$ times the residue at the pole $x=e^{i \pi}$.  (Note how important it is to get the argument correct.)  The residue at this pole is
$$\frac1{5!} \left [ \frac{d^5}{dz^5} \left ( z \log{z} \right ) \right ]_{z=e^{i \pi}} = -\frac{3!}{5!} $$
Putting this altogether, we get that
$$\int_0^{\infty} dx \frac{x}{(1+x)^6} = \frac1{20}$$
which agrees with the above.
A: Hint for the first one:
Consider the function $$f(z)=\dfrac{2}{z^{2}+4z+1}$$ and find its poles. Then use the known formula for residues:
Under the assumption that f has a pole of order $m$ at $z_{0}$, 
$$Res(z_{0},f) = \dfrac{1}{(m-1)!} \lim_{z \to z_{0}} \dfrac{d^{m-1}}{dz^{m-1}}((z-z_{0})^{m}f(z)).$$
And finally, apply the Residue Theorem.
