# Homework Help: Integration with absolute values

1. Aug 11, 2011

### Shannabel

1. The problem statement, all variables and given/known data
if f(x)=abs(x-2) and g(x)=abs(x), then solve the integral from -1 to 3 of abs(f(x)-g(x))dx

2. Relevant equations

3. The attempt at a solution
resolved absolute values:
when x<0, abs(x-2)-abs(x) = -x-2+x = 2
when 0<x<1, abs(x-2)-abs(x) = (-x+2)-x = 2-2x
when 1<x<2, abs(x-2)-abs(x) = (-x+2)-x = 2-2x
when x>2, abs(x-2)-abs(x) = x-2-x = 2

so now i have
2dx(between 0 and -1)+(2-2x)dx(between 0 and 1)+(2-2x)dx(between 1 and 2)+2dx(between 2 and 3)
= 2x(from 0 to -1) + 2x-x^2(between 0 and 1)+ 2x-x^2(between 1 and 2) + 2x(from 2 to 3)
= -2 + (2-1) + (2-1) +2 = 2

I should have had 6 as my answer, so i'm guessing that the first integral should be 2 instead of -2, but i'm not sure why.. any ideas?
also, if f(x)-g(x) is the same between 0 and 1 and 1 and 2, why is it that when i solve just between 0 and 2 i get a different answer than when i solve the two separately?

2. Aug 11, 2011

### I like Serena

Hi Shannabel!

Let's see.
I'm going to add some parentheses:

$$\int_{-1}^{3} |~ |x-2| - |x| ~| dx$$
$$= \int_{-1}^{0} 2 dx + \int_{0}^{1} (2-2x) dx + \int_{1}^{2} (2x-2) dx + \int_{2}^{3} 2 dx$$
$$= (2x) |_{-1}^0 + (2x - x^2) |_0^1 + (x^2 - 2x) |_1^2 + (2x) |_2^3$$
$$= (0 - 2\cdot -1) + ((2\cdot 1 - 1^2) - 0) +( (2^2 - 2\cdot 2) - (1^2 - 1\cdot 2)) + (2\cdot 3 - 2 \cdot 2)$$
$$= 2 + (2-1) + ((4-4)-(1-2)) + (6-4)$$
$$= 2 + 1 + 1 + 2$$
$$= 6$$

As for these questions, can you redo calculating these, this time adding parentheses where they are appropriate?

Last edited: Aug 11, 2011
3. Aug 11, 2011

### Shannabel

hi! :)

i still don't understand.. in your third step, why do you have (0-2*(-1)) instead of (0*2*(-1))?

4. Aug 11, 2011

### I like Serena

Why would you want to do a multiplication here?

To write it out more, it is:
$$(2x)|_{-1}^{0} = ((2 \cdot 0) - (2 \cdot -1))$$
This is how the result of an integral is calculated.

Btw, I made a mistake myself in my previous post! :surprised
I just edited it.
Note that your absolute value expressions are not quite right yet.

5. Aug 11, 2011

### Shannabel

oh! of course, silly me.

i don't understand why you get 2x-2 instead of 2-2x between 1 and 2?

6. Aug 11, 2011

### I like Serena

In your problem statement you say you have to integrate abs(f(x)-g(x))dx.
So you still need to take the absolute value of 2-2x between 1 and 2...
Which values does it take in that interval?

7. Aug 11, 2011

### Shannabel

abs(x-2) is negative and abs(x) is positive, no?

8. Aug 11, 2011

### I like Serena

Hmmm, (x-2) is negative and (x) is positive.
Their absolute values are both positive.

But what is the sign of (abs(x-2) - abs(x))?
And consequently, what is the expression for abs(abs(x-2) - abs(x))?

9. Aug 11, 2011

### Shannabel

it would all be negative..
so
-[(x-2)-(x)]
= -[2x+2]
= 2-2x

i'm confused!

10. Aug 11, 2011

### I like Serena

Hmmm, if I evaluate that, I get:
-[(x-2)-(x)] = -[-2] = 2

I think you dropped a minus sign somewhere. Can you correct that?

11. Aug 11, 2011

### Shannabel

yes, you're right!
but i can't find the mistake that led me to that mistake..?

12. Aug 11, 2011

### I like Serena

Well, you started by saying that (x-2) is negative for 1<x<2.
So its absolute value is -(x-2)......

13. Aug 11, 2011

### Shannabel

but then i have -x+2 right?
and then because x is positive i end up with 2...
but you ended up with 2x-2?

14. Aug 11, 2011

### I like Serena

Let's take a step back.
You (should have) had: -[-(x-2)-(x)] = ...
What do you get if you work that out?

15. Aug 11, 2011

### Shannabel

can you explain why the whole term is negative?
i don't think i understand resolving absolute values nearly as well as i thought i did..

16. Aug 11, 2011

### I like Serena

The thing to remember is that:
$$\textrm{abs}(x) = \left[ \begin{matrix} (x), & \textrm{ if x \ge 0}\\ -(x), & \textrm{ if x < 0} \end{matrix} \right.$$

We have 1<x<2.

Since (x-2) is negative, and (x) is positive, this is equal to [-(x-2)-(x)] = [2-2x]

Next step is abs(abs(x-2)-abs(x)).
This is equal to abs(2-2x), which we just derived.
Since 2-2x is negative, this is equal to -(2-2x).

17. Aug 11, 2011

### Shannabel

i'm pretty sure i understand now :)
just one other thing.. i understand why i needed to resolve with x=0 and x=2 as boundaries, since they are both zeros.. but i don't understand why i needed to use x=1?

18. Aug 11, 2011

### I like Serena

Errr... at x=0 and x=2 the complete expression is not zero.
However, the form of the expression does change, since part of the expression is an absolute value of which the argument changes sign.

So what was the expression again for 0<x<1?
And what was the expression for 1<x<2?

You should see that these are different expressions, so they have to be integrated separately.

19. Aug 11, 2011

### Shannabel

yes, but how should i have known at the beginning that the expression changes sign at x=1?
it makes sense to me that if (x-2)=0, then x=2 is a critical point and x=0 is a critical point, but i don't see where i should have got the 1?

20. Aug 11, 2011

### I like Serena

At the beginning you wouldn't know.
So you'd consider 0<x<2 as a first step and get the expression [abs(x-2)-abs(x)] = [2-2x].
But you still need to take the absolute value from this expression.
At what point does the expression [2-2x] change sign?