absolute value integrated For example I have the function $f(x) = |x^2-1| = \sqrt{(x^2-1)^2}$
$\int \sqrt{(x^2-1)^2}dx = \frac{x(x^2-3)\sqrt{(x^2-1)^2)}}{3 (x^2-1)}+constant$
But plotted it looks like this: Plot 1. There are values < 0.
I have to take the absolute value again to get the correct function.
Plot 2 Why do I have to do it again? I integrated $|x^2-1|$ and not $x^2-1$
Edit: Part 2

$x^2-1$ is positive outside of the interval $[-1,1]$.
Therefore,
$$|x^2-1| = \left\{ \begin{array}{rl} -x^2+1, & -1 \le x \le 1, \\ x^2-1, & \textrm{ otherwise}.\end{array}\right.$$
Or more completely
$$|x^2-1| = \left\{ \begin{array}{rl} x^2-1, & \textrm{ if } x < -1, \\
-x^2+1, & \textrm{ if } -1 \le x \le 1, \\ x^2-1, & \textrm{ if } x > 1.\end{array}\right.$$
Then, you integrate. We'll put the constant of integration first, because there's some trickeration involved.
$$\int |x^2-1|\ dx = C + \left\{ \begin{array}{rl} \frac{1}{3}x^3-x+c_1, & \textrm{ if } x < -1 \\ -\frac{1}{3}x^3+x+c_2, & \textrm{ if } -1 \le x \le 1,\\ \frac{1}{3}x^3-x, & \textrm{ if } x > 1. \end{array}\right.$$
Now, what are $c_1$ and $c_2$? Well, if we omitted those, then we would have discontinuities at the points $x=-1$ and $x=1$. So we need to account for a "shift" to make sure the functions are continuous, and indeed, continuous in the first derivative.
Why is there no $c_3$? Because I put the constant of integration first, and we have to choose one branch to be the "anchor". I could have put $c_1$ and $c_2$ on any branch, but I wrote it like this for convenience.
The derivatives are easy to check because the constant terms get blown out. So we must have $\frac{d}{dx}\left(\frac{1}{3}x^3-x\right) = \frac{d}{dx}\left(-\frac{1}{3}x^3+x+c_2\right)$ at $x=1$. This becomes
$$x^2-1 = -x^2+1 \implies 1^2-1=-1^2+1 \implies 0 = 0$$
which is true, so our derivative is continuous.
Then, we must have $\frac{1}{3}x^3-x = -\frac{1}{3}x^3+x+c_2$ at $x=1$. This means that $$\frac{1}{3}-1 = -\frac{1}{3}+1 +c_2 \implies c_2 = \frac{2}{3}-2 = -\frac{4}{3}.$$
Repeating this process, we want
$$\frac{1}{3}x^3-x+c_1 = -\frac{1}{3}x^3+x-\frac{4}{3}$$
at $x = -1$. We can solve again for $c_1$ to obtain
$$\frac{1}{3}-1+c_1 = -\frac{1}{3}+1-\frac{4}{3} \implies c_1 = 0.$$
Testing for continuity of the derivatives is the same as before.
This is exactly what W|A gives, except my result is shifted a bit. But that's OK, because that difference gets thrown into the integration constant, $C$.
In general, the interpretation $|x| = \sqrt{x^2}$, while correct, will sometimes only get you so far. In particular, it is possible to compute different symbolic anti-derivatives of a function such that they are equivalent, and in fact equal, over a subset of the domain of $x$, but not equivalent/not equal over other sub-domains. In such a case, it is erroneous to say that an answer that works on a specific subdomain is the "right answer." In fact, it is only the right answer precisely where it is the right answer, and nowhere else.
In these situations, we need to look at other possible interpretations, if we hope to get an answer that is the "right answer" in more places -- and perhaps everywhere. In this case, the global right answer (that is, the answer that is correct over all of the reals) is the piecewise solution.
