Evaluate $\int_0^{2\pi}\frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta \ \text{ for }\ A,B <<1$

I need to evaluate the definite integral $$\int_0^{2\pi}\frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta \ \text{ for various}\ A,B \text{; with}\ A,B<<1.$$

Wolfram Alpha provides the following indefinite general solution:-

$$\int \frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta = -(2/K) \tanh^{-1} ( \frac{A-(B-1)\tan(\theta/2)}{K})$$ where $K = \sqrt{A^2 + B^2 -1}$.

But I am having trouble checking it for the simple case when $A=B=0$ when I would expect the answer to be given by:- $$\int_0^{2\pi}\frac{1}{1 + 0 + 0}\, \mathrm{d}\theta = 2\pi.$$

I have approached the Wolfram Alpha solution thus:- $$-(2/K) \tanh^{-1} ( \frac{\tan(2\pi/2)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0/2)}{K})$$

$$-(2/K) \tanh^{-1} ( \frac{\tan(\pi)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0)}{K})$$

$$-(2/K) \tanh^{-1} ( \frac{0}{K}) +(2/K) \tanh^{-1} ( \frac{0}{K})$$

which gives the result of zero.

I presume this error comes from trying to integrate across the range $0, 2\pi$ where the $\tan$ function has singularities at $\pi/2$ and $3\pi/2$.

However when I try and break the integration into the three continuous ranges $0,\pi/2$ and $\pi/2,3\pi/2$ and $3\pi/2,2\pi$ I am still getting a result of zero thus:-

$$-(2/K) \tanh^{-1} ( \frac{\tan(2\pi/2)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(3\pi/4)}{K}) +$$ $$-(2/K) \tanh^{-1} ( \frac{\tan(3\pi/4)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(\pi/4)}{K}) +$$ $$-(2/K) \tanh^{-1} ( \frac{\tan(\pi/4)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0)}{K})$$

leading to $$-(2/K) \tanh^{-1} ( \frac{0}{K}) +(2/K) \tanh^{-1} ( \frac{-1}{K}) +$$ $$-(2/K) \tanh^{-1} ( \frac{-1}{K}) +(2/K) \tanh^{-1} ( \frac{1}{K}) +$$ $$-(2/K) \tanh^{-1} ( \frac{1}{K}) +(2/K) \tanh^{-1} ( \frac{0}{K})$$

which gives the same result of zero.

I would be grateful if somebody could tell me where I am going wrong here?

EDIT 1: I have accepted the solution provided kindly by Dr. MV. I have posted a related question which seeks to understand where my original evaluation of the definite integrand goes wrong.

EDIT 2: In the related question comments from user mickep pointed out that the wrong partitions had been used in the original evaluation. Using the correct partitions ($0...\pi$) and ($\pi...2\pi$) leads to the correct answer, for $A=B=0$, of $2\pi$ (as described in my self-answer to that same question).

EDIT 3: It was pointed out by user mickep in comments to the related question that the Wolfram Alpha solution

$$-\left(\frac{2}{K1}\right) {\arctan}h \left( \frac{A-(B-1)\tan(\theta/2)}{K1}\right)$$ where $K1= \sqrt{A^2 + B^2 -1}$.

is not as friendly as an alternative solution (reported by user mickep) which is:

$$+\left(\frac{2}{K2}\right) \arctan \left( \frac{A+(1-B)\tan(\theta/2)}{K2}\right)$$ where $K2 = \sqrt{1 - A^2 - B^2}$.

• Shall one assume $A^2+B^2>1$, so that $K$ is real? Apr 11 '17 at 15:25
• @Math-fun sorry but no. A and B are both very very small. I don't think it is too big a problem because at the end of the day K only appears as even (negative) powers so we don't have to consider imaginaries. Apr 11 '17 at 15:32
• What about the K outside of the tanh^-1? Did you include that as part of the series cancellation? If not then perhaps that's an issue Apr 11 '17 at 15:38
• @WIll Craig After expanding all the K terms in the expansions are negative and odd. Then when I apply the outer K term all the K terms becaome negative and even. In the simplified case with A=B=0 K becomes $i$ all the K terms become -1. Apr 11 '17 at 15:44
• en.wikipedia.org/wiki/Tangent_half-angle_substitution Apr 11 '17 at 15:53

Note that the integral of interest fails to converge if $\sqrt{A^2+B^2}\ge 1$. So, we restrict $A$ and $B$ such that $\sqrt{A^2+B^2}< 1$.

Then, we can write

\begin{align} \int_0^{2\pi}\frac{1}{1+A\sin(\theta)+B\cos(\theta)}\,d\theta&=\int_0^{2\pi}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta-\arctan(A/B)}\,d\theta\\\\ &=\int_{-\arctan(A/B)}^{2\pi-\arctan(A/B)}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta)}\,d\theta\\\\ &=2\int_{0}^{\pi}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta)}\,d\theta\tag1 \end{align}

where we exploited both the $2\pi$-periodicity and the evenness of the cosine function.

Next, we enforce the Weierstrass Substitution, $t=\tan(\theta/2)$, in $(1)$ to obtain

\begin{align} \int_0^{2\pi}\frac{1}{1+A\sin(\theta)+B\cos(\theta)}\,d\theta&=4\int_0^\infty \frac{1}{(1+\sqrt{A^2+B^2})+(1-\sqrt{A^2+B^2})t^2}\,dt\\\\ &=\frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}+t^2}\,dt \tag 2\\\\ &=\frac{4}{1-\sqrt{A^2+B^2}} \left.\left(\frac{\arctan\left(\frac{\sqrt{1-\sqrt{A^2+B^2}}}{\sqrt{1+\sqrt{A^2+B^2}}}t\right)}{\sqrt{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}}}\right)\right|_{0}^{\infty} \tag 3\\\\ &=\frac{2\pi}{\sqrt{1-A^2-B^2}} \tag 4 \end{align}

Note that we could have written $(2)$ as

\begin{align} \frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}+t^2}\,dt&=\frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{t^2-\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}\,dt\\\\ &=\frac{4}{\sqrt{A^2+B^2}-1}\left.\left( \frac{\text{arctanh}\left(\sqrt{\frac{\sqrt{A^2+B^2}-1}{\sqrt{A^2+B^2}+1}}t\right)}{\sqrt{\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}}\right)\right|_{0}^\infty\\\\ &=\frac{4}{\sqrt{A^2+B^2}-1}\,\left(\frac{i\pi/2}{\sqrt{\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}}\right)\\\\ &=\frac{2\pi}{\sqrt{1-A^2-B^2}} \end{align}

as expected!

• How do you transform from $A \sin theta + B \cos theta$ at the beginning? Apr 11 '17 at 16:41
• Steve, I've edited. Apr 11 '17 at 16:51
• Thanks but I still don't follow that first equation (my maths level = high school). Apr 11 '17 at 17:45
• Steve, the addition angle formula for the cosine function is $\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b)$. Let $a=\theta$ and $b=\arctan(A/B)$. Then, we see that $$\cos(\theta -\arctan(A/B))=\cos(\arctan(A/B))\cos(\theta)+\sin(\arctan(A/B))\sin(\theta)=\frac{B}{\sqrt{A^2+B^2}}\cos(\theta)+\frac{A}{\sqrt{A^2+B^2}}\sin(\theta)$$ Apr 11 '17 at 18:04
• Many thanks, I understand that now :) Next I need to study the Weierstrass Substitution. Apr 11 '17 at 19:35

A solution through complex analysis is missing, so I will provide one.
By De Moivre's identities the given integral equals

$$\int_{0}^{2\pi}\frac{e^{i\theta} d\theta} {e^{i\theta}+ \frac{A-Bi}{2}e^{2i\theta}+\frac{A+Bi}{2}}=-i\oint_{|z|=1}\frac{dz}{\frac{A-Bi}{2}z^2+z+\frac{A+Bi}{2}}$$ and that is $2\pi$ times the sum of the residues of the function $\frac{1}{\frac{A-Bi}{2}z^2+z+\frac{A+Bi}{2}}$ at its poles inside the unit circle. The poles lies at $\frac{-1\pm\sqrt{1-A^2-B^2}}{A-iB}$ and the computation is straightforward.

• Thanks. This is way above my head but can I ask whether it provides a solution for when A=B=0? Apr 12 '17 at 12:28
• @steveOw: of course. If $A=B=0$ the initial integral simply equals $$-i\oint_{|z|=1}\frac{dz}{z} = -i(2\pi i) = 2\pi$$ as expected. Apr 12 '17 at 15:59

When one of $A$ and $B$ is non-zero, then one way to figure this out for yourself is to put $$A \colon= r \cos \beta \ \mbox{ and } \ B \colon= r \sin \beta,$$ where $$r = \sqrt{A^2 + B^2} \ \mbox{ and } \ B \tan \beta = A.$$ Then \begin{align} \int_0^{2\pi} \frac{1}{1+ A \sin \theta + B \cos \theta } \mathrm{d} \theta &= \int_0^{2\pi} \frac{1}{1+r\sin(\beta + \theta) } \mathrm{d} \theta. \end{align} Can you take it from here?

As one trick, you can put $$z = \tan \frac{\beta + \theta}{2}.$$ Then $$\sin (\beta+\theta) = \frac{2z}{1+z^2} \ \mbox{ and } \ \mathrm{d} \theta = \frac{2 \mathrm{d} z}{1+z^2}.$$

When $\theta = 0$, $z= \tan \beta/2$, and when $\theta = 2\pi$, $z= \tan \left( \pi+ \beta/2 \right) = \tan \beta/2$.

So, \begin{align} \int_0^{2\pi} \frac{1}{1+ A \sin \theta + B \cos \theta } \mathrm{d} \theta &= \int_0^{2\pi} \frac{1}{1+r\sin(\beta + \theta) } \mathrm{d} \theta \\ &= 2 \int_{\tan \beta/2}^{\tan \beta/2} \frac{1}{1+2rz+z^2} \mathrm{d} \theta \\ &= 0 \end{align}

For $A = B=0$, the answer is $2\pi$, as you've correctly found out.

• thanks but I'm not sure where to go with this. Apr 11 '17 at 15:57
• I see how $=0$ (your penultimate line) arises from the previous line. But how is the general solution $=0$ consistent with the $A=B=0$ special case solution of $= 2\pi$.? Apr 11 '17 at 20:16