I'm struggling to understand the absolute value I'm struggling to understand the absolute value.
By definition we have
\begin{align*}
|x| =
\begin{cases}
-x & \text{if} \ \ x < 0,\\[2 mm]
x & \text{if} \  \ x \geq 0
\end{cases}
\end{align*}
Then my book says:
Example 1: $f(x)=|x-2|$, determine the domain, codomain and draw the graph.
\begin{align*}
f(x) = 
\begin{cases}
x - 2, & \text{if} \ \ x-2 < 0\\[2 mm]
-(x - 2),& \text{if} \ \ x-2 ≥ 0
\end{cases}
\end{align*}
I just want to know how is this related to the first definition.
How is $x - 2$ less than $0$? and why they put $-(x-2)$? And how is that $x - 2\geq 0$?
I've been trying to understand that and inequations or inequalities with absolute value, but nothing comes to my mind.
Thank you.
Note: I'm sorry in $f(x)$ I first wrote "$-x+2$, if $x-2≥0$", but the book said "$-(x-2)$". Still don't understand at all.
 A: There is an error in your book.
$|x-2| = -(x-2)$ if $x-2 < 0$.
A: If I'm understanding your question correctly, the way to think of the absolute value is that, whatever is between the bars stays positive if it was already positive, or becomes positive otherwise.  There are deeper ways to understand it as well, but that should work for your present level.
So, if we have $|x-2|$, that means that if $x-2$ dips below 0, then we will start ignoring the negative sign.
So, let's look at some $x$ values to see what this does:

*

*$x = 4$; $x - 2 = 2$, so, since it is above zero we just keep the value as-is

*$x = 3$; $x - 2 = 1$, again, we just keep the value

*$x = 2$; $x - 2 = 0$, again, we just keep the value as-is

*$x = 1$; $x - 2 = -1$, now we have a negative!  The absolute value sign means that we will convert this to a positive, so the result will be just $1$.

*$x = 0$; $x - 2 = -2$.  Negative again.  So we convert to a positive, so the result will be $2$.

*$x = -1$; $x - 2 = -3$.  Still negative (and will continue to be so as $x$ moves lower).  Therefore we will have to keep changing the sign to make it positive.

The reason why they put $-(x - 2)$ is that, if the result of $x - 2$ is a negative, that can make it a positive by negating the result. For instance, if I have $-1$ and negate it, then $- -1 = 1$.
A: Hoping you are aware of slopes of straight lines and how they are found by using the equation of that  particular line.
for f(x)=|x| you can see it as a y=|x| if it is plotted on the x-y axis then
then according to defination of modulus function y=x if x>=0 and y=-x if x<0
notice it cannot be y=-x if -x<0 because x is already a negative number and hence
-x<0 for it would not be true.
now back to y=|x| for case 1-->  x>=0; y=x hence a straight line through the origin and at an angle of 45deg(pi/4 rad)
for case 2--> x<0; y=-x hence a straight line perpendicular line to our initial line
and passing through the origin
hence both lines pass through the origin notice that the parts of these straight lines below the x axis(i.e. -y-axis) will not be there when we consider the modulus function defination
NOW COMING TO f(x)=|x-2|
we can do the same thing to this one also consider x-2=z
then our function becomes f(x)=|z|
hence applying our defination of modulus function to it
for CASE 1--> z>=0; y=z or y=x-2
therefore for x-2>=0; x>=2
now y=x-2 is a straight line passing through (2,0) making an angle of 45deg(pi/4 rad)
for CASE 2--> z<0; y=-z or y=-(x-2)
therefore for x-2<0; x<2
now y=-(x-2) => y=-x+2
y=-x+2  is a straight line perpendicular the line in case 1 and passes through the same point on x axis (2,0)
as before the part of both the lines below the x axis is not there when we consider the graph of a modulus function.
