# How to integrate $|x| \cdot x$

How to integrate this manually? $$\int |x|\cdot x ~dx$$

My tries so far:

$$\int |x|\cdot x ~dx = (x^2/2)\cdot|x| - \int (x²/2)\cdot \mathop{\mathrm{sign}}(x) ~dx$$ Trying it again, but using sign(x) as first parameter, because sign(x) is not derivable further. $$\int \mathop{\mathrm{sign}}(x)\cdot(x²/2) ~dx =|x|\cdot (x^2/2) - \int |x|\cdot x ~dx$$ Great, as nothing would have been done.

Next try, using the signum function $$|x|\cdot x = \mathop{\mathrm{sign}}(x)\cdot x^2$$

$$\int \mathop{\mathrm{sign}}(x)\cdot |x| ~dx = x^2-\int|x|\cdot x^2~dx$$

$$\int |x|\cdot x^2 ~dx =x²\cdot \mathop{\mathrm{sign}}(x)\cdot x^2-\int x^2\cdot \mathop{\mathrm{sign}}(x)\cdot 2x ~dx$$

which seems to be a never ending chain again. Any ideas?

• if this is a definite integral in your actual problem, you can split it along the integration interval, e.g. $$\int_{-s}^t |x| \cdot x dx = \int_0^t x^2dx - \int_{-s}^0 x^2 dx = \frac{t^3+s^3}{3}.$$ – gt6989b Nov 20 '17 at 22:19
• $sign(x) \cdot \frac{x^3}{3}$ ? – valer Nov 20 '17 at 22:19
• @valer That's $\frac{|x|^3}{3}$ . – Gribouillis Nov 20 '17 at 22:24
• @gt6989b it is an indefinite integral – little raspy Nov 20 '17 at 22:28

## 4 Answers

$\begin{eqnarray} \int x|x|\,dx&=&\int x|x|\cdot\frac{x}{x}\,dx\\ &=&\int x^2\cdot\frac{|x|}{x}\,dx \end{eqnarray}$

Let $u=|x|$. Then $du=\frac{|x|}{x}\,dx$.

So

\begin{eqnarray} \int x^2\cdot\frac{|x|}{x}\,dx&=&\int u^2\,du\\ &=&\frac{u^3}{3}+c\\ &=&\frac{1}{3}x^2|x|+c \end{eqnarray}

For $x>0$, this is the integral of $x^2$ which is $\frac{x^3}{3}$. For $x<0$, is the integral of $-x^2$, which is $-\frac{x^3}{3}$. This is just $\frac{|x^3|}{3}$

\begin{align*} \int x|x|\,dx &= \int_c^x t|t|\,dt \\ &= \begin{cases}\begin{cases} \int_c^x t^2\, dt, & c\ge 0 \\ \int_0^x t^2\,dt - \int_c^0 t^2\,dt, & c < 0\end{cases}, & x\ge 0 \\ \begin{cases} \int_x^0 t^2\, dt - \int_0^c t^2\,dt, & c\ge 0 \\ -\int_c^x t^2\,dt, & c < 0\end{cases}, & x< 0\end{cases} \\ &= \begin{cases}\begin{cases} \frac 13(x^3-c^3), & c\ge 0 \\ \frac 13(x^3 +c^3), & c < 0\end{cases}, & x\ge 0 \\ \begin{cases} -\frac 13(x^3+c^3), & c\ge 0 \\ -\frac 13(x^3-c^3), & c < 0\end{cases}, & x< 0\end{cases} \\ &= \frac 13|x|^3 + \text{const}\end{align*}

I will use the sign function $\text{sgn} (x)$ you attempted to use in your original solution to the problem.

The sign function is defined as $$\text{sgn} (x) = \begin{cases} -1, & x < 0\\ 0, & x = 0\\ 1 & x > 0. \end{cases}$$ So we see the sign function is independent of $x$ for all real $x$. Also, since for all real $x$ we have $$|x| = \text{sgn}(x) \cdot x,$$ the integral can be rewritten as $$\int x \cdot |x| \, dx = \int x \cdot (\text{sgn} (x) \cdot x) \, dx = \text{sgn}(x) \int x^2 \, dx.$$ Integrating we have $$\int x \cdot |x| \,dx = \text{sgn}(x) \cdot \frac{x^3}{3} + C = \frac{x^2}{3} \cdot (\text{sgn}(x) \cdot x) + C = \frac{x^2 |x|}{3} + C.$$