# How to evaluate the integral $\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$?

When I was trying to solve the integral $$\int\frac{\sin x+\cos x}{\sqrt{1+\sin2x}}dx$$ by using $$(1+\sin2x)=(\sin x+\cos x)^2$$, I obtained this integral $$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$$ where $$|\cdot|$$ is the absolute value function. If this problem were a definite integral then I would have simplified the denominator by removing the absolute value function. But here it's an indefinite integral. So, how to proceed further?

In my book, the integral $$\int\frac{\sin x+\cos x}{\sqrt{1+\sin2x}}dx$$ was solved by expressing the denominator of the integrand as $$\sqrt{2-(\sin x-\cos x)^2}$$ and then using the method of substitution $$t=(\sin x-\cos x)$$, $$dt=(\sin x+\cos x)dx$$ and so on. I totally understood this method but I'm interested in solving the integral $$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$$ to obtain the final result.

The final result obtained by the method outlined in the book is $$\sin^{-1}\sin(x-\pi/4)+C$$. It would be helpful if you could explain how to obtain this result by evaluating the integral in the question.

• $\int\frac{f(x)}{|f(x)|}dx=x\frac{f(x)}{|f(x)|}+C$ Dec 20, 2019 at 8:10
• @mathlove, Thank you. That was helpful. But could you please tell, is it possible to obtain the result $\sin^{-1} \sin(x-\pi/4)+C$ by this method? Based on your comment, I'm able to only say the integral equals $x \frac{f(x)}{|f(x)|}$ where $f(x)=\sin x+\cos x$. Dec 22, 2019 at 14:54
• I converted my comment into an answer with more details. Dec 23, 2019 at 5:59

I'll convert my comment into an answer with more details.

One can have $$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx=x\times\frac{\sin x+\cos x}{|\sin x+\cos x|}+C$$

You've written the following as an answer : $$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx=\sin^{-1}\bigg(\sin\bigg(x-\frac{\pi}{4}\bigg)\bigg)+C$$

For $$m\in\mathbb Z$$, we have \begin{align}&x\times\frac{\sin x+\cos x}{|\sin x+\cos x|} \\\\&=\begin{cases}x&\text{if \quad\sin x+\cos x\gt 0}\\ -x&\text{if \quad\sin x+\cos x\lt 0}\end{cases} \\\\&=\begin{cases}x&\text{if \quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi}\\ -x&\text{if \quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}}\end{cases} \\\\&=\begin{cases}(x-\frac{\pi}{4})-2m\pi+\frac{\pi}{4}+2m\pi&\text{if \quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi}\\ -(x-\frac{\pi}{4})+(2m-1)\pi-\frac{\pi}{4}-(2m-1)\pi&\text{if \quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}}\end{cases} \\\\&=\begin{cases}\sin^{-1}(\sin(x-\frac{\pi}{4}))+\frac{\pi}{4}+2m\pi&\text{if \quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi}\\ \sin^{-1}(\sin(x-\frac{\pi}{4}))-\frac{\pi}{4}-(2m-1)\pi&\text{if \quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}}\end{cases} \\\\&=\sin^{-1}\bigg(\sin\bigg(x-\frac{\pi}{4}\bigg)\bigg)+(\text{constant})\end{align}

• Thank you for your answer. With respect to the last two steps, why does the arbitrary constant depend on the range of values that $x$ can take? I can see the constant doesn't depend on $x$ but differs from one condition to the other. Is this possible? Dec 23, 2019 at 6:13
• A small correction - add $x$ to $\cos$ in the first condition :-) I was unable to do the edit because of the edit threshold Dec 23, 2019 at 6:25
• @M.GuruVishnu: Thanks, corrected it. I'm not sure if I understood your question correctly. Are you asking why $\sin x+\cos x\gt 0$ if and only if $2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi$ where $m$ is any integer? Dec 23, 2019 at 6:27
• No. I understood that step. I was referring to the last before step where the arbitrary constant in the first condition $\frac {\pi}{4}+2m\pi$ and in the second $-\frac {\pi}{4}-(2m-1)\pi$ are different and depend on the interval in which $x$ lies. Is this possible? Shouldn't the constant be same in both the cases, or it doesn't matter? Dec 23, 2019 at 6:38
• @M.GuruVishnu: Yes, it is possible. You might want to see the graph of $\sin^{-1}(\sin(x-\frac{\pi}{4}))$. You'll see that the graph is periodic and that it does depend on $m$. So, the constants have to be different. Finally, it does not matter since we just want to prove that the two functions differ only by a constant. Dec 23, 2019 at 6:49

Use the identity $$\sin(x)+\cos(x) = \sqrt{2}\sin\left(x+\frac{\pi}{4}\right) = \sqrt{2}\cos\left(x-\frac{\pi}{4}\right)$$ to get that

$$\frac{\sin(x)+\cos(x)}{|\sin(x)+\cos(x)|} = \operatorname{sgn}\left(\sin\left(x+\frac{\pi}{4}\right)\right)$$

We can find its antiderivative graphically, it is a triangle wave with crests/troughs at $$x = k\pi - \frac{\pi}{4}$$ for $$k\in\mathbb{Z}$$. The triangles have slope $$\pm 1$$ and can be elevated by any arbitrary constant $$C$$.

• Thank you for your answer. But I've some trouble in understanding because of two reasons: (1) How to determine the antiderivative graphically? (2) I didn't get a triangle wave in a graphing calculator (desmos). Dec 20, 2019 at 7:30
• @M.GuruVishnu That's because you graphed the derivative, not the antiderivative. Dec 20, 2019 at 8:25

Hint: notice, that if you place $$t=\sin{x} + \cos{x}$$, the integrated function becomes $$\frac{t}{|t|}=sign(t)$$. Since integral is just an area under function, we need to have limits provided.

• Thank you for the hint. I already realised this was looking like a signum function. But graphically, I think this function is much more complicated than the original signum function. Is there any formula to evaluate integral for signum function? I think I'm unaware of them. Dec 20, 2019 at 7:03
• @M.GuruVishnu There is no general formula, we can only split it into parts where $t$ is positive and negative. Dec 20, 2019 at 7:05
• Ok. If we were provided limits as I said in the question we could remove the absolute value function. But what if we don't know when $t$ is positive or negative? Further, I understand definite integral is area under the curve, but here it's an indefinite integral and only the shape of the curve is defined and not its position on the graph due to the presence of the arbitrary constant. Dec 20, 2019 at 7:08
• @M.GuruVishnu in our example$t=\sqrt{2} \sin{(x+\frac{\pi}{4})}$, so the integral will be constant Dec 20, 2019 at 7:10
• Sorry, I didn't get how the integral will be a constant. The final result obtained (as given in the question) depends on $x$. Dec 20, 2019 at 7:43

Hint:

The integrand will be undefined if $$\sin x+\cos x=0$$

$$|\sin x+\cos x|=\sqrt2\left|\cos\left(x-\dfrac\pi4\right)\right|=\begin{cases} (\sin x+\cos x)&\mbox{if } \cos\left(x-\dfrac\pi4\right)\ge0 \\ -(\sin x+\cos x) & \mbox{if } \cos\left(x-\dfrac\pi4\right)<0 \end{cases}$$

Now $$\cos\left(x-\dfrac\pi4\right)\ge0$$ if $$2m\pi-\dfrac\pi2\le x-\dfrac\pi4\le2m\pi+\dfrac\pi2\iff2m\pi-\dfrac\pi4\le x\le 2m\pi+\dfrac{3\pi}4$$

• Thank you for the hint. I understood that if we were given the ranges then I could have eliminated the absolute value function. But could you please tell what if we aren't given the limits? Dec 20, 2019 at 7:12
• @M.GuruVishnu, For plotting we need the ranges, then only we can define teh function Dec 20, 2019 at 7:24
• Ok. Is it really necessary to plot this on the graph to evaluate the indefinite integral? Is it impossible to solve the indefinite integral by this method? Dec 20, 2019 at 7:26
• @M.GuruVishnu, Unless we can define a function, it can not be integrated or differentiated Dec 20, 2019 at 7:33