# Integration with absolute values

• Shannabel
In summary: Well, if you have something like: abs(-x) - abs(-y) then that equals abs(x) - abs(y).But note that, for example, abs(-x) is not the same as -x.It is the same as x.

## Homework Statement

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

## 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?

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

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?

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

Last edited:
I like Serena said:
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} (2-2x) dx + \int_{2}^{3} 2 dx$$
$$= (2x) |_{-1}^0 + (2x - x^2) |_0^1 + (2x - x^2) |_1^2 + (2x) |_2^3$$
$$= (0 - 2\cdot -1) + ((2\cdot 1 - 1^2) - 0) +( (2\cdot 2 - 2^2)- (1\cdot 2 - 1^2)) + (2\cdot 3 - 2 \cdot 2)$$
$$= 2 + (2-1) + ((4-2)-(2-1)) + (6-4)$$
$$= 2 + 1 + 1 + 2$$
$$= 6$$

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

hi! :)

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

Shannabel said:
hi! :)

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

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!
I just edited it.
Note that your absolute value expressions are not quite right yet.

I like Serena said:
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!
I just edited it.
Note that your absolute value expressions are not quite right yet.

oh! of course, silly me.

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

Shannabel said:
oh! of course, silly me.

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

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?

I like Serena said:
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?

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

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

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))?

I like Serena said:
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))?

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

i'm confused!

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

i'm confused!

Hmmm, if I evaluate that, I get:
-[(x-2)-(x)] = -[-2] = 2 I think you dropped a minus sign somewhere. Can you correct that?

I like Serena said:
Hmmm, if I evaluate that, I get:
-[(x-2)-(x)] = -[-2] = 2 I think you dropped a minus sign somewhere. Can you correct that?

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

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

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

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

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?

Shannabel said:
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?

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

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

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

Shannabel said:
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..

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

I like Serena said:
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).

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?

Shannabel said:
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?

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.

I like Serena said:
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.

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?

Shannabel said:
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?

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?

I like Serena said:
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?

i got it, thanks!: )

Shannabel said:

## Homework Statement

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

## The Attempt at a Solution

resolved absolute values:
when x<0, abs(x-2)-abs(x) = -x-2+x = 2   should be abs(x-2)-abs(x) = -(x-2)+x = 2

when 0<x<1, abs(x-2)-abs(x) = (-x+2)-x = 2-2x   These two could be written as one.
when 1<x<2, abs(x-2)-abs(x) = (-x+2)-x = 2-2x   These two could be written as one.

when x>2, abs(x-2)-abs(x) = x-2-x = 2   should be abs(x-2)-abs(x) = x-2-x = 2
...

Here's the first part of your Original Post.

See corrections and/or comments in RED.

I like Serena said:
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).

by this same logic, shouldn't i have
if x>2, abs(abs(x-2)-abs(x)) = -(abs(x-2-x)) = -(2)
since abs(x-2) and abs(x) are positive but abs(abs(x-2)-abs(x)) is negative?
i know it should be a positive 2 since that gets me to the right answer... but i don't see why?

Shannabel said:
by this same logic, shouldn't i have
if x>2, abs(abs(x-2)-abs(x)) = -(abs(x-2-x)) = -(2)
since abs(x-2) and abs(x) are positive but abs(abs(x-2)-abs(x)) is negative?
i know it should be a positive 2 since that gets me to the right answer... but i don't see why?

Can you calculate (x-2-x) again?

I like Serena said:
Can you calculate (x-2-x) again?

lol... thankyou :)