Find $ \int \frac{\sec x(2+\sec x)}{(1+2\sec x)^2}\,dx$

calculusindefinite-integralsintegration

Find $\displaystyle \int \frac{\sec x(2+\sec x)}{(1+2\sec x)^2}\,dx$

I couldn't find my answer so I looked up the solution which is as follows
$$\displaystyle \begin{align}&\int \frac{\sec x(2+\sec x)}{(1+2\sec x)^2}\,dx\\&= \int \frac{2\cos x+1}{(2+\cos x)^2}\,dx\\&= \int \frac{2\cos x+\cos^2 x+\sin^2 x}{(2+\cos x)^2}\,dx\\&=\int \frac{\cos x}{2+\cos x}\,dx+\int \frac{\sin^2 x}{(2+\cos x)^2}\,dx\\&=\frac{1}{2+\cos x}\cdot(\sin x)-\int \sin x\cdot\frac{\sin x}{(2+\cos x)^2}\,dx+\int \frac{\sin^2 x}{(2+\cos x)^2}\,dx\\&=\frac{\sin x}{2+\cos x}+C\end{align}$$
I was stuck with $\displaystyle\int \frac{2\cos x+1}{(2+\cos x)^2}\,dx$ and didn't think of replacing $1$ with $\cos^2 x+\sin^2 x$. I want to know the motivation behind this because the reason of this substitution wasn't very obvious to me at first and it only became clear to me in the second last step. Other ways to solve this are also welcome.

Best Answer

Using the "universal substitution": $$\begin{align} \int \frac{\sec x(2+\sec x)}{(1+2\sec x)^2}dx &= \int\frac{(\tan^2(x/2) + 1)\left(2+ \frac{\tan^2(x/2) + 1}{1-\tan^2(x/2)}\right)}{(1-\tan^2(x/2))\left(1+\frac{\tan^2(x/2) + 1}{1-\tan^2(x/2)}\right)^2} \\ &= \begin{bmatrix}u = \tan(x/2) \\ du = \frac{1}{2}\sec^2(x/2)dx\end{bmatrix} \\ &= -2 \int \frac{u^2-3}{(u^2 + 3)^2}du,\end{align}$$ which can be integrated using the known algorithms. However, the original solution is indeed more attractive.

Related Question