Solving $\int_{0}^{2\pi}\frac{d\phi}{2+\sin(\phi)}$ with complex exponentials I’m working through the textbook A First Course in Complex Analysis and I’m trying to solve problem 4.30:

Compute the real integral
$$\int_{0}^{2\pi}\frac{d\varphi}{2+\sin(\varphi)}$$
by writing the sine function in terms of the complex exponential and making the substitution $z=e^{i\varphi}$ to turn the real integral into a complex integral.

I started by rewriting the sine function as $\frac{e^{i\varphi}-e^{-i\varphi}}{2i}$:
$$=\int_{0}^{2\pi} \frac{d\varphi}{2+\tfrac{e^{i\varphi}-e^{-i\varphi}}{2i}}=2i\int_{0}^{2\pi} \frac{d\varphi}{4i+e^{i\varphi}-e^{-i\varphi}}$$
Then I substituted $z=e^{i\varphi}$, as the problem asked, and got $dz=izd\varphi$, so $d\varphi=\tfrac{-idz}{z}$. I also defined my path as $\gamma:[0,2\pi]\rightarrow \mathbb{C}$ as $\gamma(\varphi)=e^{i\varphi}$
$$=2i\int_{\gamma} \frac{1}{4i+z-\tfrac{1}{z}} \frac{-idz}{z}=2\int_{\gamma} \frac{dz}{z^2+4iz-1}$$.
We can see that the inside of the integral is a rational function, so it should be holomorphic everywhere where it’s defined. The poles can then be calculated by the quadratic equation as $\pm \sqrt{3}i-2i$.
However, these poles clearly lie outside of the region enclosed by $\gamma$, the unit circle.
Since the inside of the integral is defined and holomorphic on all points on $\gamma$ and inside $\gamma$, and $\gamma$ is a closed curve, we have:
$$2\int_{\gamma} \frac{dz}{z^2+4iz-1}=2\cdot0=0$$
However, this is very obviously wrong, because the original integral is always positive and hence can’t be zero.
So my questions are:

*

*Where is my mistake?

*How would you solve this correctly?


Here is another approach that relies on Calculus II.
We have
$$
I=\int_0^{2\pi}\frac{dx}{2+\sin x}=\int_{0}^{\pi}\frac{dx}{2+\sin x}+\int_{\pi}^{2\pi}\frac{dx}{2+\sin x}
$$
Setting $y=x-\pi/2, z=x-3\pi/2$ in the first and second integral, respectively, we get
\begin{eqnarray}
I&=&\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dy}{2+\sin\left(y+\frac{\pi}{2}\right)}+\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dz}{2+\sin\left(z+\frac{3\pi}{2}\right)}\cr
&=&\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dy}{2+\cos y}+\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dz}{2-\cos z}\cr
&=&\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dx}{2+\cos x}+\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\frac{dx}{2-\cos x}
\end{eqnarray}
Let $t=\tan(x/2)$. Since
$$
\cos x=\frac{1-t^2}{1+t^2}
$$
and
$$
dx=\frac{2dt}{1+t^2}
$$
we get
\begin{eqnarray}
I&=&\int_{-1}^{1}\frac{1}{2+\frac{1-t^2}{1+t^2}}\cdot\frac{2dt}{1+t^2}+
\int_{-1}^{1}\frac{1}{2-\frac{1-t^2}{1+t^2}}\cdot\frac{2dt}{1+t^2}\cr
&=&\int_{-1}^{1}\frac{2}{2(1+t^2)+1-t^2}dt+
\int_{-1}^{1}\frac{2}{2(1+t^2)-(1-t^2)}dt\cr
&=&4\int_{0}^{1}\frac{1}{3+t^2}dt+
4\int_{0}^{1}\frac{1}{1+3t^2}dt\cr
&=&4\int_{0}^{1}\frac{1}{3+t^2}dt+
\frac{4}{3}\int_{0}^{1}\frac{1}{\frac{1}{3}+t^2}dt\cr
&=&\frac{4}{\sqrt{3}}\left[\tan^{-1}\left(\frac{t}{\sqrt{3}}\right)\right]_0^1+\frac{4\sqrt{3}}{3}\left[\tan^{-1}(\sqrt{3}t)\right]_0^1\cr
&=&\frac{4}{\sqrt{3}}\left[\tan^{-1}\left(\frac{1}{\sqrt{3}}\right)-\tan^{-1}(0)+\tan^{-1}(\sqrt{3})+\tan^{-1}(0)\right]\cr
&=&\frac{4}{\sqrt{3}}\left(\frac{\pi}{6}+\frac{\pi}{3}\right)\cr
&=&\frac{4}{\sqrt{3}}\cdot\frac{\pi}{2}\cr
&=&=\frac{2\pi}{\sqrt{3}}.
\end{eqnarray}
