TITLE: Evaluate $\int\frac{\cos x}{\sin x + \cos x}\,\text{d}x$.
QUESTION [5 upvotes]: I'm trying to figure out how to take this indefinite integral:
$$ \int\frac{\cos x}{\sin x + \cos x}\,\text{d}x.$$
I tried simplifying and rearranging it, and this is the best I got:
$$\int\frac{1}{\tan x + 1 }\,\text{d}x.$$
But I still can't figure out how to integrate from there. I know that it's integrable, as Wolfram Alpha indicates that the integral is $ \frac{1}{2}\big(x+\ln{(\sin x + \cos x)}\big)+C$, but I can't figure out the steps to deriving it. Does anyone know how to evaluate this integral?

REPLY [5 votes]: Notice that
$$\sin x+\cos x=\sqrt{2}\left(\frac{1}{\sqrt{2}}\sin x+\frac{1}{\sqrt{2}}\cos x\right)=\sqrt{2}\sin\left(x+\frac{\pi}{4}\right)$$
Therefore
$$I=\frac{1}{\sqrt{2}}\int\frac{\cos x}{\sin\left(x+\frac{\pi}{4}\right)}dx$$
Now let $x+\frac{\pi}{4}=t$
$$I=\frac{1}{\sqrt{2}}\int\frac{\cos \left(t-\frac{\pi}{4}\right)}{\sin t}dt=\frac{1}{2}\int\frac{\sin t + \cos t}{\sin t}dt=\frac{1}{2}\left(t+\ln {\left|\sin t\right|}\right)+C_1\\=\frac{1}{2}\left(x+\frac{\pi}{4}+\ln {\left|\sin x+\cos x\right|}\right)+C_1=\frac{1}{2}\left(x+\ln {\left|\sin x+\cos x\right|}\right)+C$$