How to evaluate $\int _{0}^{\frac{\pi}{2}} \frac{\mathrm dx}{a+\cos x}$ using contour integration? I want to evaluate:
$\displaystyle \int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\cos x} \tag*{}$
With my basic knowledge of Cauchy Residue theorem:
\begin{align*}
\int_0^{\frac{\pi}{2}} \frac{\mathrm dx}{a + \cos x}  &= \int_0^{\frac{\pi}{2}}\frac{\mathrm dx}{a + \frac{e^{ix} + e^{-ix}}{2}}  \\
&= 2\int_0^{\frac{\pi}{2}} \frac{e^{ix} \ \mathrm dx}{2ae^{ix} + e^{2ix} + 1} && \text{Let } z=e^{ix}, \text{ so } \mathrm dz = ie^{ix} \ \mathrm dx. \\
&= \frac{2}{i} \int_{|z|=1} \frac{\mathrm dz}{z^2 + 2az + 1} \\
&= \frac{2}{i} \int_{|z|=1} \frac{\mathrm dz}{(z-z_1)(z-z_2)}
\end{align*}
where the circle $|z|=1$
My problem is how to proceed further from here? How do I draw circle? Clockwise or Counterclockwise?
 A: I doubt you can use contour integration to handle this since you can't obtain a closed curve. Noting
$$ \cos x=\frac{1-\tan^2(\frac x2)}{1+\tan^2(\frac x2)}$$
one has, under $\tan(\frac x2)\to t$,
\begin{eqnarray}
&&\int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\cos x} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\frac{1-\tan^2(\frac x2)}{1+\tan^2(\frac x2)}} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{(1+\tan^2(\frac x2))\mathrm dx}{a(1+\tan^2(\frac x2))+1-\tan^2(\frac x2)} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{(1+\tan^2(\frac x2))\mathrm dx}{(a+1)+(a-1)\tan^2(\frac x2))} \\
&=&\int_0^1\frac{2}{(a+1)+(a-1)t^2}\mathrm dt\\
&=&\frac2{\sqrt{a^2-1}}\arctan\bigg(\sqrt{\frac{a-1}{a+1}}\bigg).
\end{eqnarray}
A: Your substitution gives$$\begin{align}\int_1^i\frac{-2idz}{(z+a)^2+1-a^2}&=\left[\frac{-2i}{\sqrt{1-a^2}}\arctan\frac{z+a}{\sqrt{1-a^2}}\right]_1^i\\&=\frac{2}{\sqrt{1-a^2}}\operatorname{artanh}\sqrt{\frac{1-a}{1+a}}.\end{align}$$It's technically a contour integral; it's just the contour isn't closed, so it's a "normal" integration evaluation technique, rather than one using the residue theorem. As for how the last $=$ works, I'll leave you to work through the trigonometric identities.
A: You have to parameterize the complex number. If you are integrating over a circle then you will have that if
$$z=Re^{i\theta}$$
then
$$R = 1$$
$$\theta = \lambda$$
$$z = e^{i\lambda}$$
$$dz = ie^{i\lambda}d\lambda$$
Then your integral becomes
$$2\int_0^{\pi/2}\frac{e^{i\lambda}d\lambda}{e^{2i\lambda}+2ae^{i\lambda}+1} $$
which you can solve as a typical integral.
