Explanation of an integration trick for $\int \frac{a_1 \cos x + b_1 \sin x}{a\cos x + b\sin x}dx$

Any linear combination of sine waves with the same period and different phase shifts can be written as a single sine wave with that same period and a suitable phase shift. \begin{align} & A\cos(x+\varphi) + B\cos(x+ \psi) \\[8pt] = {} & A\big(\cos x\cos\varphi - \sin x \sin\varphi\big) \\ & {} + B\big(\cos x\cos\psi - \sin x \sin \psi\big) \\[8pt] = {} & C\cos x + D\sin x \end{align} where \begin{align} C & = A\cos\varphi + B \cos\psi \\[8pt] D & = -A\sin\varphi - B\sin\psi \end{align} and then \begin{align} & C\cos x + D\sin x \\[8pt] = {} & \sqrt{C^2+D^2} \left( \frac C {\sqrt{C^2+D^2}} \cos x + \frac D {\sqrt{C^2+D^2}} \sin x\right) \\[8pt] = {} & \sqrt{C^2+D^2} \big( E\cos x + F\sin x\big). \end{align} We now have $E^2+F^2=1$ so $E= \cos\chi$ and $F=\sin\chi$ for some angle $\chi.$ Thus we have \begin{align} & E\cos x + F\sin x \\[8pt] = {} & \cos\chi\cos x + \sin\chi\sin x \tag 1 \\[8pt] = {} & \cos(x-\chi). \end{align} Line $(1)$ above is what you have in the problem you're facing.


You could also do it in a standard way. Since this is a rational function of trigonometric functions, we know trigonometric substitutions work. In this case, $u=\tan x$ is a good one. We have $\mathrm{d}u=\sec^2 x\mathrm{d}x$, $\mathrm{d}x=\frac{\mathrm{d}u}{1+u^2}$ and so $$ \begin{align} \int \frac{a_1 \cos x + b_1 \sin x}{a\cos x + b\sin x}\,\mathrm{d}x &= \int \frac{a_1 + b_1 \tan x}{a + b\tan x}\,\mathrm{d}x \\ &= \int \frac{a_1 + b_1u}{(a + bu)(1+u^2)}\,\mathrm{d}u \end{align}$$ Then you find partial fraction decomposition $$\frac{a_1 + b_1u}{(a + bu)(1+u^2)}=\frac{A}{a + bu}+\frac{Bu+C}{1+u^2} $$ and the integral is $$\frac Ab\ln|a+bu|+\frac B2\ln(1+u^2)+C\tan^{-1}(u)+\text{constant} $$ which simplifies (using the values of $A,B$ and $C$) to $$\frac Ab \ln|a\cos x+b\sin x|+Cx+\text{constant}$$ Note that after back-substituting $u=\tan x$, you need to get rid of the tangent because it introduces discontinuities at $\cos x=0$, and you don't have these in the integrand.


Steps to solve this:

  1. Write the denominator as $a \cos x + b \sin x = r \cos (x + \alpha)$.

  2. Substitute $t = x + \alpha$ and rewrite the integrand as $$\frac{a_1 \cos (t - \alpha) + b_1 \sin (t - \alpha)}{r \cos t}.$$

  3. Use addition formulae in the numerator and obtain an integral that is easily computed: $$\int \frac{a_2 \cos t + b_2 \sin t}{\cos t} \, dt = a_2 t - b_2 \log \cos t + C.$$