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?
 A: If direct way can be considered, just as Dr.MW already answered, tangent half-angle substitution $t=\tan \frac \theta 2$ makes the problem simple since $$I=\int\frac{(1+sin(\theta))}{(3+cos(\theta))}d\theta=\int\frac{(t+1)^2}{t^4+3 t^2+2}dt=\int \frac{2 t}{t^2+1} dt+\int\frac{1-2 t}{t^2+2}dt$$ $$I=\log \left(1+t^2\right)+\frac{\tan ^{-1}\left(\frac{t}{\sqrt{2}}\right)}{\sqrt{2}}-\log \left(2+t^2\right)=\frac 1{\sqrt{2}}\tan ^{-1}\left(\frac{t}{\sqrt{2}}\right)+\log\Big(\frac{1+t^2}{2+t^2} \Big)$$ Back to $\theta$ (if required), $$I=\frac{1}{\sqrt 2}\tan ^{-1}\left(\frac{\tan \left(\frac{\theta }{2}\right)}{\sqrt{2}}\right)-\log (3+\cos (\theta ))$$ So, since, as explained by  Dr.MW,$$
\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
$$ the bounds for $t$ are $-\infty$ and $+\infty$, so the logarithmic terms does not contribute and the result is just $\frac{\pi}{\sqrt 2}$.
More generally, assuming $a \leq \pi$,$$\int_{-a}^{a} \frac{1+\sin \theta}{3 + \cos \theta} d\theta=\sqrt{2} \tan ^{-1}\left(\frac{a}{\sqrt{2}}\right)$$
A: 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!
