# Integrate $\int \frac{dx}{a\sin x+b\cos x}$

As far as I know, we could use the stereographic change of variables where $$\tan(\frac{x}{2})=t$$, $$\sin x=\frac{2t}{1+t^2}$$ and $$\cos x= \frac{1-t^2}{1+t^2}$$, then replace $$dx$$ also $$\sin x$$ and $$\cos x$$, and finally I get something like this: $$\int \frac{-2\,dt}{bt^2-2at-b}$$ Now, I may think the next step it's some algebra. How would you proceed?

• take the scale factor of $-2$ out of the integrand, factorise and perform a partial fraction decomposition. warning: it is a very messy process though. – thesmallprint May 27 '19 at 18:50
• Yeah, thanks, I thought about it, but went to large. Wondering if there is something faster without use "tricks" – ClaraGarcía May 27 '19 at 18:54
• duplicate of math.stackexchange.com/q/377117 – Jean Marie May 28 '19 at 8:20

There's a simpler way. Take $$\theta$$ such that $$\cos\theta=\frac a{\sqrt{a^2+b^2}}$$ and that $$\sin\theta=\frac b{\sqrt{a^2+b^2}}$$. Let $$r=\sqrt{a^2+b^2}$$. Then\begin{align}\int\frac{\mathrm dx}{a\sin x+b\cos x}&=\frac1r\cdot\int\frac{\mathrm dx}{\sin(x+\theta)}\\&=-\frac1r\log\bigl(\cot(x+\theta)+\csc(x+\theta)\bigr).\end{align}Can you take it from here?

• Thanks! Mmhh, is the answer $\frac{1}{r}In|\frac{1-cos(x+\theta)}{sin(x+\theta)}|$? but I think you use a equivalent expression for $\int cscx$ – ClaraGarcía May 27 '19 at 19:10
• Yes, that's equal to the function that I got. Note that, for any $\alpha$,$$\left(\csc(\alpha)+\cot(\alpha)\right)\times\left(\csc(\alpha)-\cot(\alpha)\right)=\frac1{\sin^2(\alpha)}-\frac{\cos^2(\alpha)}{\sin^2(\alpha)}=1.$$Therefore,$$\log\left(\csc(\alpha)+\cot(\alpha)\right)=-\log\left(\csc(\alpha)-\cot(\alpha)\right).$$ – José Carlos Santos May 27 '19 at 21:08

$$bt^2-2at-b=b\left[t^2-2\frac abt-1\right]=b\left[\left(t-\frac ab\right)^2-\left(1+\frac{a^2}{b^2}\right)\right]$$ now use substitution to get it in the form: $$\int\frac{dx}{x^2-1}=\frac 12\ln\left(\frac{x-1}{x+1}\right)+C$$

If I were doing this myself, I'd prefer José Carlos Santos' method---which among other unadvertised benefits (1) doesn't introduce a problem at odd integer multiples of $$\pi$$ (see below) and (2) doesn't break the symmetry of the roles of $$a$$ and $$b$$.

Here's a conventional way to finish using your approach: Completing the square in the denominator (temporarily assuming $$b \neq 0$$) gives $$-b t^2 + 2 a t + b = - b \left[\left(t - \frac{a}{b}\right)^2 - \left(\frac{a^2}{b^2} + 1\right)\right] .$$ So, applying the translation substitution $$u = t - \frac{a}{b}$$ leaves the standard integral $$-\frac{2}{b} \int \frac{du}{u^2 - \lambda^2}, \qquad \lambda := \frac{\sqrt{a^2 + b^2}}{b} .$$

The integrand can be decomposed using partial fractions as $$\frac{1}{u^2 - \lambda^2} = \frac{1}{2 \lambda}\left(\frac{1}{u - \lambda} - \frac{1}{u + \lambda}\right)$$ and then immediately integrated.

With some algebraic manipulation the resulting antiderivative $$F(\theta)$$ can be written using an expression valid even for $$b = 0$$; to justify that this antiderivative is still valid in that case, we need only verify that $$F'(x)$$ coincides with the original integrand.

NB that the given substitution $$t = \tan \frac{x}{2}$$ presupposes that $$x$$ is not an odd integer multiple of $$\pi$$, and so the antiderivative we produce by reversing this substitution after integrating is not a priori valid on intervals that contain such a value.

• Thanks! This is a great answer! At the end I get $\frac{-1}{b}ln|\frac{g-\lambda}{g+\lambda}|+c$ right? As Henry pointed as well. I just have to specify the problem of odd integers multiples of $\pi$. – ClaraGarcía May 27 '19 at 20:33
• You're welcome, I'm glad you found it useful. And yes, that's correct, provided you replace $g$ with $u$. Also, you can absorb the negative sign by replacing the argument of $\log$ with its reciprocal. Notice that there's nothing special about the original integrand at odd multiples of $\pi$, at least for generic values of $a, b$, so in that sense the substitution $t = \tan \frac{x}{2}$ isn't ideal for the problem. A better option would be to take $t=\tan\frac{x + \theta}{2}$ for a $\theta$ that aligns the $x$-values where $t$ blows up with the $x$-values where the original integrand blows up, – Travis Willse May 27 '19 at 21:29
• ...but this is in spirit what José's answer already achieves by rewriting the original integrand as a multiple of $\csc (x + \theta)$. – Travis Willse May 27 '19 at 21:31