Trigonometric and absolute value integral $\int_0^{\pi/2} \left|\sin x - \cos2x\right| \, dx$ Problem:
Evaluate$$\int_0^{\pi/2} \left|\sin x - \cos2x\right| \, dx.$$
How would I go about this with the absolute value sign? Is there a general rule for absolute values and Integrals?
 A: Moving from $x=0$ to $x=\pi/2$, notice $\sin x$ moving upward from $0$ to $1$ as $\cos(2x)$ moves downward from $1$ to $-1$.  So they pass each other at some point, and the question is where that point is.  Call it $c$.  If $0\le x\le c$ then $\sin x\le\cos(2x)$, so $|\sin x-\cos(2x)| = \cos(2x)-\sin x$.  If $c<x\le\pi/2$ then $\sin x>\cos(2x)$, so $|\sin x - \cos(2x)| = \sin x - \cos(2x)$.  Thus the integral becomes
$$
\int_0^c (\cos(2x) - \sin x)\,dx + \int_c^{\pi/2} (\sin x-\cos(2x))\,dx.
$$
Next, what number is $c$?  You have $\sin c=\cos(2c)$.  So
\begin{align}
\sin c & = \cos(2c) = \cos^2c-\sin^2c = 1 - 2\sin^2 c. \\[10pt]
u & = 1 - 2u^2.
\end{align}
This quadratic equation has solutions $u=\dfrac 1 2$ and $u=-1$.  Clearly $\sin x=-1$ is not between $0$ and $\pi/2$, so you need to know for which value of $c$ between $0$ and $\pi/2$ you have $\sin c= \dfrac 1 2$.
A: First find the roots of the function in the range $[0,\frac\pi2]$.
$$\sin x-\cos(2x)=\sin x+2\sin^2x-1=(\sin x+1)(2\sin x-1).$$
There is a single solution, $x=\dfrac\pi6$, and the function is negative, then positive.
This yields
$$I=-\int_0^{\pi/6}(\sin x-\cos 2x)dx+\int_{\pi/6}^{\pi/2}(\sin x-\cos 2x)dx$$ which is elementary.
A: 
Is there a general rule for absolute values and Integrals?

Yes.  In general, for $\int_a^b |f(x)| \, dx$, we want to know where $f(x)$ is positive and where it's negative on the interval $[a,b]$.  This is because $|f(x)| = f(x)$ if $f(x) > 0$, and $|f(x)| = -f(x)$ if $f(x) < 0$.  This follows directly from the definition of the absolute value function.
In this case, we're integrating $|\sin x - \cos 2x|$ on $[0, \pi/2]$.  So we want to know where $f(x) = \sin x - \cos 2x$ is positive and negative on $[0, \pi/2]$.  We can easily do this by graphing the function, but if we aren't able to for whatever reason then here's how we do it algebraically.  We start by finding out where $f(x) = 0$ on $[0,\pi/2]$.
\begin{align}
  \sin x - \cos 2x &= 0\\
  \sin x - (1 - 2\sin^2 x) &= 0\\
  2\sin^2x + \sin x - 1 &= 0\\
  (2\sin x - 1)(\sin x + 1) &= 0
\end{align}
Therefore we have $2\sin x - 1 = 0$, which means $\sin x = 1/2$ and therefore $x = \pi/6$, or we have $\sin x + 1 = 0$, which means $\sin x = -1$, but this has no solutions in $[0,\pi/2]$.  So the only value of $x \in [0,\pi/2]$ where $f(x) = 0$ is $x = \pi/6$.
Now we want to know two things:


*

*Is $f(x)$ positive or negative for $0 < x < \pi/6$?

*Is $f(x)$ positive or negative for $\pi/6 < x < \pi/2$?


There are many ways to approach.  You can choose one test value in each interval and evaluate $f(x)$ at each test value.  You can note that $f(0) < 0$ and $f(x)$ is continuous, therefore $f(x) < 0$ on $(0, \pi/6)$.  You can then note that $f'(x) > 0$ on $(0,\pi/2)$ and so $f(x) > 0$ on $(\pi/6, \pi/2)$, etc.  Anyway, I prefer the first method because it's the easiest, although if you don't remember your trig identities it'll require a calculator.
$f(\pi/12) < 0$ and $f(\pi/4) > 0$.  Therefore, $f(x) < 0$ on $(0,\pi/6)$ and $f(x) > 0$ on $(\pi/6, \pi/2)$, and we have
\begin{align}
  \int_0^{\pi/2} |\sin x - \cos 2x| \, dx &= \int_0^{\pi/6} |\sin x - \cos 2x | \, dx + \int_{\pi/6}^{\pi/2} | \sin x - \cos 2x| \, dx\\[0.3cm]
  &= \int_0^{\pi/6} -(\sin x - \cos 2x ) \, dx + \int_{\pi/6}^{\pi/2} \sin x - \cos 2x \, dx\\[0.3cm]
\end{align}
