Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Today, one of my student found the following integral and asked me for its solution:

$$\int|x|\; dx$$

I used some formal methods for it, but it seems I need a magic trick. I wish, I am noting a valuable question here for others. Thanks for your time.

share|cite|improve this question
What is the magic trick? – Tunococ Nov 27 '12 at 20:19
@Tunococ: I didn't note that I could break the integral respect to $x>0$ and $x<0$ as Chris did below. Shame! I was thinking about a wrong way. Sorry. – Babak S. Nov 27 '12 at 20:25
up vote 4 down vote accepted

For $x>0$, $|x|=x$, so has antiderivative $\frac{x^2}{2}$. For $x<0$, $|x|=-x$, and so has antiderivative $-\frac{x^2}{2}$. Thus we should consider the function $$f(x)=\begin{cases}\frac{x^2}{2} & x>0 \\-\frac{x^2}{2} & x \le 0 \end{cases}$$ It's not hard to check from first principles that $f'(0)=0$, and so $f$ is indeed an antiderivative of $|x|$. Of course, so is $f+c$ for any constant $c$.

share|cite|improve this answer
For those not fond of "cases" constructs: You may use $\frac{x\cdot|x|}2$ – Hagen von Eitzen Nov 27 '12 at 20:25
@HagenvonEitzen: Honestly, I wanted to note that, but you did. Yes it is $\frac{x|x|}{2}$. Thanks both of you. – Babak S. Nov 27 '12 at 20:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.