Compute $\int_{a}^{b}\left|x\right|\mathrm{d}x$ The reason I ask this is because $$\int_{x=a}^{x=b}\left|x\right|\mathrm{d}x$$  gives exactly the same result as $$\int_{x=a}^{x=b}x\mathrm{d}x=\frac{b^2}{2}-\frac{a^2}{2}=\int_{x=a}^{x=b}\left|x\right|\mathrm{d}x$$ when $0 \leq a \leq b$
But for a non trivial case could someone please show the steps of integration of $$\int_{x=a}^{x=b}\left|x\right|\mathrm{d}x$$ for $-7\le a\le 8$ and $0\le b\le 12$.
Thank you.
 A: This is not true in general, and depends on $a$ and $b$:
$$\int_{-1}^1 xdx =0 $$
but
$$\int_{-1}^1 \lvert x\rvert dx = 2\int_{0}^1 \lvert x\rvert dx = 1.  $$
What you mention clearly holds if $0 \leq a \leq b$ (since anyway in this case $x=\lvert x \rvert$ for $x\in[a,b]$).
Edit:
If $a < 0$, b$>0$, then
$$\begin{align}
\int_a^b \lvert x\rvert dx &= \int_a^0 \lvert x\rvert dx + \int_0^b \lvert x\rvert dx = \int_a^0 (-x)  dx+ \int_0^b x dx = \int_0^a x  dx+ \int_0^b x dx\\
&=
 \frac{b^2+a^2}{2}
\end{align}
$$
while
$$\begin{align}
\int_a^b x dx &= \frac{b^2-a^2}{2}
\end{align}
$$
A: Note that $|x| = \frac{d}{dx}\frac{x^2 (\text{sgn}\ x)}{2}$. Here, $\text{sgn}:\Bbb R → \Bbb R$ is the sign function, 
$$ \text{sgn}\ (x) = \begin{cases} +1 & x>0 \\ 0 & x=0 \\ -1 & x<0 \end{cases} $$
Thus we see that 
$$ ∫_a^b |x| \ dx = \frac{b^2 (\text{sgn}\ b) - a^2 (\text{sgn}\ a)}{2}$$
This formula works for all $a,b\in\Bbb R$. For example, if $a,b>0$ it does indeed reduce to $\frac{a^2 - b^2}{2}$. We also obtain if $0<a=-b$, $\int_a^b |x| \ dx = \frac{a^2 + b^2}{2}$. These are the special cases given by the other answers. 
A: I think that the easiest way of doing this algebraically is to note that
$$
\int |x|\,dx=\frac{1}{2}x|x|=
\begin{cases}
\frac{1}{2}x^2, & x\geq 0,\\
-\frac{1}{2}x^2, & x<0,
\end{cases}
$$
since $D(x^2/2)=x$, which coincides with $|x|$ for $x\geq 0$, and $D(-x^2/2)=-x$, which coincides with $|x|$ for $x<0$. Thus, by the so-called fundamental theorem of calculus,
$$
\int_a^b |x|\,dx=\frac{1}{2}\bigl(b|b|-a|a|\bigr).
$$
A: Notice, as per given intervals, we have  


*

*$a<0$, $b\geq 0$ $$\int_{x=a}^{x=b}|x|dx=\int_{a}^{0}|x|dx+\int_{0}^{b}|x|dx$$


$$=\int_{a}^{0}(-x)dx+\int_{0}^{b}(x)dx$$$$=-\left[\frac{x^2}{2}\right]_{a}^{0}+\left[\frac{x^2}{2}\right]_{0}^{b}$$ $$=\frac{a^2}{2}+\frac{b^2}{2}=\frac{a^2+b^2}{2}$$
2. $a\geq 0$, $b\geq 0$ $$\int_{x=a}^{x=b}|x|dx=\int_{a}^{b}xdx=\left[\frac{x^2}{2}\right]_{0}^{b}$$$$=\frac{b^2}{2}-\frac{a^2}{2}=\frac{b^2-a^2}{2}$$
