<s>[INST] Residue Integration I am attempting to calculate the integral of $\frac{(1+sin(\theta))}{(3+cos(\theta))}$ from $0$ to $2\pi$. I have already changed $sin$ and $cos$ into $\frac{1}{2i(z-z^{-1})}$ and $\frac{1}{2(z+z^{-1})}$. I am really stuck now. Can anyone please guide me?
 [/INST] Since the integrand is periodic, then
$$\begin{align}
\int_0^{2\pi} \frac{1+\sin \theta}{3 + \cos \theta} d\theta&=\int_{-\pi}^{\pi} \frac{1+\sin \theta}{3 + \cos \theta} d\theta\\
&=\int_{-\pi}^{\pi} \frac{1}{3 + \cos \theta} d\theta
\end{align}$$
where we exploited the fact that $\frac{\sin \theta}{3+\cos \theta}$ is an odd function.
Next, let $u=\tan (\theta /2)$ so that $du = \frac12 \sec^2(\theta /2)$, and $\cos \theta =\frac{1+u^2}{1-u^2}$.  Then, we find the anti-derivative of $\frac{1}{3+\cos \theta}$ is $\frac{\sqrt{2}}{2} \arctan (\sqrt{2}\tan (\theta /2)/2) +C$.  Evaluating the anti-derivative between limits of integration reveals
$$\int_{-\pi}^{\pi} \frac{1}{3+\cos \theta} d\theta =\frac{\sqrt{2}\pi}{2}$$

Now, let's use contour integration.
Let $z=e^{i \theta}$ so that $d\theta=dz/(iz)$.
Next note that
$\frac{1+\sin \theta}{3+\cos \theta}=\frac{z^2+2iz-1}{i(z^2+6z+1)}$.  The only root of the denominator that lies inside the unit circle is at $z=-3+2\sqrt{2}$.
Now the integral of interest is
$$-\int_C \frac{z^2+2iz-1}{z(z^2+6z+1)} dz$$
The integral has two simple poles, one at $0$ and the other at $-3+2\sqrt{2}$.  The evaluation of the integral therefore is, by the Residue Theorem,
$$2\pi i \sum \text{Res} \left(- \left( \frac{z^2+2iz-1}{z(z^2+6z+1)}\right)\right)$$
The residue at $z=0$ is found by evaluating the term $- \frac{z^2+2iz-1}{z^2+6z+1}$ at $z=0$.  We find this first residue to be 1.
The residue at $z=-3+2\sqrt{2}$ is found by evaluating the term $-\frac{z^2+2iz-1}{z(z+3+2\sqrt{2})}$ at $z=-3+2\sqrt{2}$.  We find this second residue to be $-1-i\sqrt{2}/4$.
Putting it all together recovers the aforementioned result!
</s>