Evaluating $\int_{-\pi}^{\pi}\frac{1}{ai+b\cos(x)}dx$ for real $a,b$ I want to do following integrals
\begin{align}
\int_{-\pi}^{\pi}\frac{1}{ai+b\cos(x)}dx
\end{align}
where $a,b$ are real 
Frist my trial was using the ideas of complex analysis, but here I don't know whether the poles are inside $|z|<1$ or not. (Since i didn't fix the magnitude of a and b)
any ideas? To this integral be finite, do i have to restrict the magnitude of $|a|$ and $|b|$ (i.e. |a|<|b|) 
For the simple case, via mathematica i can obtain some results, for example setting a=1 or b=1 case. I want to know how to calculate such integrals.  
For $a+b\cos(\theta)$ case, introducting complex variables or parametrizing cos(x) into functions of $tan^2(x/2)$ i can do the integral without any problem, but i want to do it in more general
 A: Let $t=\tan(x/2)$ then $dx=\frac{2dt}{1+t^2}$ and $\cos(x)=\frac{1-t^2}{1+t^2}.$ So you want:
$$\begin{align}\int_{-\infty}^{\infty}\frac{2\,dt}{ai(1+t^2)+b(1-t^2)}&=\int_{-\infty}^{\infty}\frac{2dt}{(b+ai)+(-b+ai)t^2}\\
&=2(b+ai)\int_{-\infty}^{\infty} \frac{dt}{(b+ai)^2-(a^2+b^2)t^2}
\end{align}$$
Letting $w=b+ai$ then this is:
$$\int_{-\infty}^{\infty}\frac{2w\,dt}{w^2-|w|^2t^2}$$
Now, $$\frac{2w}{w^2-|w|^2t^2}=\frac{1}{w-|w|t} +\frac{1}{w+|w|t}$$
So the indefinite integral is $$\frac{1}{|w|} \left(\log\frac{w+|w|t}{w-|w|t}\right)$$
Now, $\dfrac{w+|w|t}{w-|w|t}\to -1$ as $t\to\infty$ and $t\to-\infty,$ but it appraches $-1$ from different directs.
So the integral is $\pm\dfrac{2\pi i}{|w|},$ where the sign is the opposite of the sign of $a.$ 
The sign is because when $t$ is positive, and $a>0,$ the angle to get from $w-|w|t$ to $w+|w|t$ is clockwise rotation, while when $a<0$ this rotation is counter-clockwise. 

The answer can be rewritten as:
$$\frac{2\pi}{ai\sqrt{1+\frac{b^2}{a^2}}}$$
From this, we see that we should try to show:
$$\int_{-\pi}^{\pi}\frac{dx}{1+ci\cos x}=\frac{2\pi}{\sqrt{1+c^2}}$$
Then if $c=\frac{-b}{a}$ then we'd get (almost) our original integral.
If $f(x)=\frac{1}{1+ci\cos x}=\frac{1-ci\cos x}{1+c^2\cos^2 x}$, then $f(x+\pi)=\overline{f(x)}$, so the imaginary part of the integral is zero, and thus we are reduced to showing:
$$\int_{-\pi}^{\pi}\frac{dx}{1+c^2\cos^2 x}=\frac{2\pi}{\sqrt{1+c^2}}$$
Now, we're done if you can show:
$$\int_{-\pi/2}^{\pi/2}\frac{dx}{1+c^2\cos^2 x}=\frac{\pi}{\sqrt{1+c^2}}$$
Letting $t=\tan x$ then $dx=\frac{dt}{1+t^2}, \cos^2 x=\frac{1}{1+t^2}$ amd you need to show:
$$\int_{-\infty}^{\infty} \frac{dt}{1+c^2+t^2}=\frac{\pi}{\sqrt{1+c^2}}$$
which is a fairly standard integral.
A: Recall that $\cos(x)=\frac{1}{2}(e^{ix}+e^{-ix})$, so we have 
$$\int_{-\pi}^\pi\frac{dx}{ai+b\cos x}=\int_{-\pi}^\pi\frac{dx}{ai+\frac{b}{2}(e^{ix}+e^{-ix})}=\frac{1}{i}\int_{-\pi}^\pi\frac{ie^{ix}dx}{\frac{b}{2}e^{2ix}+iae^{ix}+\frac{b}{2}}.$$
Use change of variable $z=e^{ix}$ and let $\gamma$ be the unit circle with counter clockwise orientation.  Then we have 
$$\int_{-\pi}^\pi\frac{dx}{ai+b\cos x}=-i\int_\gamma\frac{dz}{\frac{b}{2}z^2+iaz+\frac{b}{2}}.$$
Notice that $\frac{b}{2}z^2+iaz+\frac{b}{2}=\frac{b}{2}(z-z_+)(z-z_-)$, where $z_\pm=\frac{i}{b}\left[-a\pm\sqrt{a^2+b^2}\right]$.  We will split into cases.  
Case 1: assume $a>0$.
In this situation, $|z_+|<1$ and $|z_-|>1$.  We can now apply Residue Theorem.
$$-i\int_\gamma\frac{dz}{\frac{b}{2}z^2+iaz+\frac{b}{2}}=\frac{-2i(2\pi i)}{b}\frac{1}{2\pi i}\int_\gamma\frac{dz}{(z-z_+)(z-z_-)}=\frac{4\pi}{b}\frac{1}{z_+-z_-}=\frac{-2\pi i}{\sqrt{a^2+b^2}}$$
Case 2: assume $a<0$.
In this situation, $|z_+|>1$ and $|z_-|<1$.  We can now apply Residue Theorem as before.
$$-i\int_\gamma\frac{dz}{\frac{b}{2}z^2+iaz+\frac{b}{2}}=\frac{-2i(2\pi i)}{b}\frac{1}{2\pi i}\int_\gamma\frac{dz}{(z-z_+)(z-z_-)}=\frac{4\pi}{b}\frac{1}{z_--z_+}=\frac{2\pi i}{\sqrt{a^2+b^2}}$$
Case 3: $a=0$
The integral does not converge when $a=0$ (unless we talk about principal value integrals).
In conclusion,
$$\int_{-\pi}^\pi\frac{dx}{ai+b\cos x}=\frac{\mp 2\pi i}{\sqrt{a^2+b^2}}$$
for $\text{sgn}\left(a\right)=\pm1$ and is divergent when $a=0$.
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

$\ds{\mc{I}\pars{a,b} \equiv \int_{-\pi}^{\pi}{\dd x \over a\ic + b\cos\pars{x}}\,,\qquad a, b \in \mathbb{R}}$.

Note that $\ds{\bbx{\left.\mc{I}\pars{a,0}\,\right\vert_{\ a\ \not=\ 0} =
-\,{2 \over a}\,\pi\ic}}$. Then $\ds{\pars{~\mbox{with}\ a \not= 0\,,\ b \not= 0\ \mbox{and}\
\mu \equiv {a \over b} \in \mathbb{R}~}}$,
\begin{align}
\left.\rule{0pt}{5mm}\mc{I}\pars{a,b}\,\right\vert_{\ b\ \not=\ 0} & \equiv
{2 \over b}\int_{0}^{\pi}{\dd x \over \mu\ic + \cos\pars{x}} =
{2 \over b}\int_{-\pi/2}^{\pi/2}{\dd x \over \mu\ic - \sin\pars{x}}
\\[5mm] & =
{2 \over b}\int_{0}^{\pi/2}\bracks{{1 \over \mu\ic - \sin\pars{x}} +
{1 \over \mu\ic + \sin\pars{x}}}\dd x =
{4\mu \over b}\,\ic\int_{0}^{\pi/2}{\dd x \over -\mu^{2} - \sin^{2}\pars{x}}
\\[5mm] & =
-\,{4\mu \over b}\,\ic\int_{0}^{\pi/2}{\sec^{2}\pars{x} \over \mu^{2}\sec^{2}\pars{x}  + \tan^{2}\pars{x}}\dd x =
-\,{4\mu \over b}\,\ic\int_{0}^{\pi/2}{\sec^{2}\pars{x} \over \pars{\mu^{2} + 1}
\tan^{2}\pars{x}  + \mu^{2}}\dd x
\\[5mm] & =
-\,{4\over b\mu}\,\ic\,{\verts{\mu} \over \root{\mu^{2} + 1}}\int_{0}^{\pi/2}{\root{\mu^{2} + 1}\sec^{2}\pars{x}/\verts{\mu} \over 
\bracks{\root{\mu^{2} + 1}\tan\pars{x}/\verts{\mu}}^{2}  + 1}\dd x\quad
\pars{\begin{array}{l}
\mbox{Note that this}
\\
\mbox{step requires}
\\
\ds{\mu \not= 0}
\\
\ds{\implies a \not= 0}
\end{array}}
\\[5mm] & =
-\,{4\,\mrm{sgn}\pars{\mu}\over b\root{\mu^{2} + 1}}\,\ic
\int_{0}^{\infty}{\dd t \over  t^{2}  + 1}\dd x =
-\,{2\,\mrm{sgn}\pars{\mu}\over b\root{\mu^{2} + 1}}\,\pi\ic =
-\,{2\,\mrm{sgn}\pars{a/b} \over b\root{a^{2}/b^{2} + 1}}\,\pi\ic
\\[5mm] & =
-\,{2\,\mrm{sgn}\pars{a} \over \root{a^{2} + b^{2}}}\,\pi\ic\qquad a \not= 0.
\end{align}

$$
\bbx{\int_{-\pi}^{\pi}{\dd x \over a\ic + b\cos\pars{x}} =
\left\{\begin{array}{lcl}
\ds{-\,{2 \over a}\,\pi\ic} & \ds{\mbox{if}} & \ds{a \not = 0\,,\quad b = 0}
\\[2mm]
\ds{-\,{2\,\mrm{sgn}\pars{a} \over \root{a^{2} + b^{2}}}\,\pi\ic} &
\mbox{if} &  \ds{a \not = 0\,,\quad b \not= 0}
\\[2mm]
\mbox{diverges} && \mbox{otherwise}
\end{array}\right.}
$$
