Definite Integral questions Evaluate the definite integral of the function.
$$ \int_{-\pi/4}^{\pi/2} \; |\sin x| \; dx $$
My solution was :
$$ \cos \left(\frac{\pi}{2}\right) - \cos\left(\frac{-\pi}{4}\right)$$
$$ \frac{-\sqrt2}{2} $$
But the answer in the book is  $ 2 - \frac{\sqrt2}{2} $. So what's wrong with my solution ?
 A: Observe that $\displaystyle \sin x \text{ is }\begin{cases} <0 &\mbox{if } -\frac\pi2\le y<0 \\\ge0 & \mbox{if } 0\le y\le\frac\pi2 \end{cases}$
Again we know for real  y, $\displaystyle |y|=\begin{cases} +y &\mbox{if } y\ge0 \\-y & \mbox{if } y<0 \end{cases} $
A: You seem to have neglected the absolute value signs.  The derivative of $\cos x$ is $\sin x$, not $|\sin x|$.  So you cannot apply the fundamental theorem of calculus the way you did. $\int_a^b f(x)\;dx = g(b) - g(a)$ only when $f$ is the derivative of $g$, and that is not the case in your proposed solution.  You have instead calculated $\int_{-\pi/4}^{\pi/2} \sin x\;dx$, which is different.
The usual technique to deal with this kind of problem is to divide the interval of integration into pieces on which the integrand is simpler.  For example, $|x| = x$ when $x$ is positive and $-x$ when $x$ is negative, so it is easy to integrate on intervals where its argument doesn't change sign; on such intervals $|f(x)|$ can be replaced by $f(x)$, if $f(x)$ is positive, and by $-f(x)$, if $f(x)$ is negative.  
In this case we divide the interval of integration $\left[-\frac\pi4, \frac\pi2\right]$ into two parts, $L = \left[-\frac\pi4, 0\right]$
and
$R = \left[0, \frac\pi2\right]$.  On interval $L$, $\sin x$ is everywhere negative, and $|\sin x| = -\sin x$; on interval $R$, $\sin x$ is everywhere positive, and $|\sin x| = \sin x$.  This allows us to get rid of the absolute value signs, as follows:
$$\begin{align}
\int_{-\pi/4}^{\pi/2} \; |\sin x| \; dx &= 
\int_{-\pi/4}^0 \; |\sin x| \; dx 
+
 \int_0^{\pi/2} \; |\sin x| \; dx\\
& = 
\int_{-\pi/4}^0 \; -\sin x \; dx 
+
 \int_0^{\pi/2} \; \sin x \; dx
\end{align}
$$
Now we can apply the fundamental theorem of calculus to the two terms on the right:
$$
\begin{align}
\hphantom{\int_{-\pi/4}^{\pi/2} \; |\sin x| \; dx} &= 
\cos x\left.\right|_{-\pi/4}^0 +
-\cos x\left.\right|_0^{\pi/2} \\ &=
\left(1 - \frac{\sqrt2}2\right) - \left(0-1\right) \\&=
2-\frac{\sqrt2}2
\end{align}
$$
A: Since $\sin x$ is nonpositive in $\left[-\dfrac{\pi}{4},0\right]$ and nonnegetive in $\left[0,\dfrac{\pi}{2}\right]$
$$\int_{-\pi/4}^{\pi/2}|\sin x|=\int_{\pi/4}^0(-\sin x)dx+\int_0^{\pi/2}\sin x~dx=-\int_{\pi/4}^0\sin x~dx+\int_0^{\pi/2}\sin x~dx$$
Evaluate it to obtain your desired result.
