2
$\begingroup$

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

  • 0
    The anti-derivative must take the integration range into account somewhere.2012-11-07
  • 0
    The function you get after taking the absolute value is not "the correct function". Its derivative is clearly negative for $x<2$, whereas $f(x)$ is not negative there or anywhere else.2012-11-07
  • 0
    The best way to do an integral involving absolute value is subdivide into cases, positive or negative inside.2012-11-07
  • 0
    The anti-derivative must be valid over the range of integration. It is not defined at $x=\pm 1$, so to use it directly, you must constrain your range to lie within one of the three ranges $X<-1$, $x\in [-1,1]$, or $x>1$. If your range does not fit within one of these, you need to split the range accordingly and sum the results.2012-11-08

3 Answers 3

3

$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.

  • 0
    [integration](http://www.wolframalpha.com/input/?i=integrate+sqrt%28%28x^2-1%29^2%29)2012-11-07
  • 0
    and [derivative](http://www.wolframalpha.com/input/?i=derivate+%28x+%28x^2-3%29+sqrt%28%28x^2-1%29^2%29%29%2F%283+%28x^2-1%29%29)2012-11-07
  • 1
    @Gunnar: To repeat, WolframAlpha's evaluation of the integral does not appear to be correct. An antiderivative should be a continuous function.2012-11-07
  • 0
    Yes but clearly that cannot be correct, because a factor of $x$ appears, meaning the function will be negative if $x$ is negative. On the other hand, the piecewise form avoids this issue. Consider this link: [Link](http://www.wolframalpha.com/input/?i=integrate+|x^2-1|)2012-11-07
  • 0
    Okay, but I don't really see, where the mistake happens. If I'm just looking at $\sqrt{(x^2-1)^2}$ and forget about $|x^2-1|$ I have a function, that is > 0 for all x. When I integrate it, I get the function I've written in my question. But where happens the mistake? When I derivate the function, I get $\sqrt{(x^2-1)^2}$ again.2012-11-07
  • 2
    Because that integral *only* works if you're in the domain $x \ge 0$. Think of it this way. Say you're standing on the edge of a cliff. If you take one step backward, you're on solid ground, then if you step forward, you're back where you started. However, it is not true that if you step forward first, and then back, that you will end up where you started.2012-11-07
  • 0
    It doesn't work for x>=0. It only works for 0 < x < 1.2012-11-07
  • 0
    So you are not simply standing on a cliff, but rather the top of a skyscraper 1 unit wide.2012-11-07
  • 0
    So [this](http://www.wolframalpha.com/input/?i=integrate+|x^2-1|) would be correct? How can I calculate this?2012-11-07
  • 0
    Yes. You would calculate it by breaking up $|x^2-1|$ as I have posted in my answer :)2012-11-07
  • 0
    But how do I get to $1/12 ((-3 x^3+9 x+4) sgn(x+1)+sgn(1-x) ((-x^3+3 x+4) sgn(x+1)-3 (x^3-3 x+4))+3 x^3-9 x+20)$2012-11-07
  • 0
    Integrate each "branch" of the piecewise function independently; then you need to add an offset to make sure that your branches line up and are smooth.2012-11-07
  • 0
    $\frac{2}{3}-2 = \frac{2}{3}-\frac{6}{3} = \frac{2-6}{3} = -\frac{4}{3}$2012-11-07
  • 0
    @Gunnar I have added to my answer to address the "mistake" that you are looking for. Basically you are differentiating a function over a region where it is not defined everywhere.2012-11-07
1

WA is giving a function whose derivative equals your $f$ everywhere except at two discontinuities. WA's algorithm for antidifferentiating must do different things depending upon what interval of $x$-values are under consideration. If you take WA's function and view it as a piecewise funciton with three pieces, you do indeed have an antiderivative except at the points where the discontinuities are. All you need to do to get the continuous antiderivative that you are expecting is shift the right-most piece of the graph that WA gave up, and shift the left piece down.

This can be accomplished by adding a step function to WA's answer.

$$\frac{x(x^2-3)\sqrt{(x^2-1)^2)}}{3 (x^2-1)}+2/3\frac{|x-1|}{x-1}+2/3\frac{|x+1|}{x+1}$$

This function is still undefined at $x=\pm1$, but the two-sided limit exists at each point, so it can be "glued" back together there:

$$\begin{cases}2/3,&x=1\\-2/3,&x=-1\\\frac{x(x^2-3)\sqrt{(x^2-1)^2)}}{3 (x^2-1)}+2/3\frac{|x-1|}{x-1}+2/3\frac{|x+1|}{x+1},&\text{else}\end{cases}$$


In response to a comment of th OP in a different answer, when you differntiate WA's antiderivative: $\frac{x(x^2-3)\sqrt{(x^2-1)^2)}}{3 (x^2-1)}$ using the chaing rule, quotient rule, etc., you are violating the conditions for the use of those rules, because you are applying them to a function that is not continuous. This function with this formula is not defined at $x=\pm1$. And that is the "mistake" that OP is looking for.

1

To evaluate $\int_a^b |x^2-1|dx$ there are 6 possibilities depending on where $a,b$ lie. I am assuming $a\leq b$ in the following, if $a>b$ then use $\int_a^b = -\int_b^a$.

If $a,b \in (-\infty,-1]$ or $a,b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (b^3-3b-a^3+3a)$.

If $a,b \in (-1,1)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (a^3-3a-b^3+3b)$.

If $a\in (-\infty,-1], b \in (-1,1)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (4-a^3+3a-b^3+3b)$.

If $a\in (-1,1), b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (4+a^3-3a+b^3-3b)$.

If $a \in (-\infty,-1]$, $b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (8-a^3+3a+b^3-3b)$.