Math Core

Lesson 1.2 · Functions and Linear Systems

Piecewise and absolute value functions

A phone plan charges a flat fee up to a data limit and then a per-gigabyte rate after that. A parking garage charges one price for the first hour and another for each hour after. In situations like these, one formula isn't enough: the rule changes depending on the input. Functions built this way are called piecewise functions, and the absolute value function is the most famous one.

What a piecewise function is

Definition

Piecewise function

A piecewise function uses different formulas on different parts of its domain. Each formula comes with a condition that says which inputs it applies to:

f(x)={formula 1,if x is in interval 1formula 2,if x is in interval 2f(x) = \begin{cases} \text{formula 1}, & \text{if } x \text{ is in interval 1} \\ \text{formula 2}, & \text{if } x \text{ is in interval 2} \end{cases}

To evaluate a piecewise function, first decide which condition the input satisfies, then use only that formula. Each input gets exactly one output, so the conditions never overlap.

Worked example: Evaluating a piecewise function

Let

f(x)={2x+1,x<1x2,1≤x≤310−x,x>3f(x) = \begin{cases} 2x + 1, & x < 1 \\ x^2, & 1 \le x \le 3 \\ 10 - x, & x > 3 \end{cases}

Find f(−2)f(-2), f(1)f(1), f(3)f(3) and f(5)f(5).

  • −2<1-2 < 1, so use the first piece: f(−2)=2(−2)+1=−3f(-2) = 2(-2) + 1 = -3.
  • 11 satisfies 1≤x≤31 \le x \le 3 (not x<1x < 1), so use the second piece: f(1)=12=1f(1) = 1^2 = 1.
  • 33 satisfies 1≤x≤31 \le x \le 3: f(3)=32=9f(3) = 3^2 = 9.
  • 5>35 > 3, so use the third piece: f(5)=10−5=5f(5) = 10 - 5 = 5.

Common mistake

Pay close attention to the boundary values. At x=1x = 1 above, it's tempting to use 2x+12x + 1 because it's listed first, but the condition x<1x < 1 does not include 11. Check << versus ≤\le every time you land exactly on a boundary.

Graphing piecewise functions

Graph each piece as if it were a whole function, but draw only the part over its own interval. Then mark each endpoint:

  • a closed dot (filled) when the endpoint is included (≤\le or ≥\ge),
  • an open dot (hollow) when it is not included (<< or >>).

Worked example: Graphing three pieces

Graph

f(x)={x+4,x<−1x2,−1≤x≤21,x>2f(x) = \begin{cases} x + 4, & x < -1 \\ x^2, & -1 \le x \le 2 \\ 1, & x > 2 \end{cases}

Left piece. The line y=x+4y = x + 4 for x<−1x < -1. At x=−1x = -1 it would reach y=3y = 3, but −1-1 is not included, so draw an open dot at (−1,3)(-1, 3) and draw the line to the left.

Middle piece. The parabola y=x2y = x^2 from x=−1x = -1 to x=2x = 2. Both ends are included: closed dots at (−1,1)(-1, 1) and (2,4)(2, 4).

Right piece. The horizontal line y=1y = 1 for x>2x > 2, with an open dot at (2,1)(2, 1).

The three pieces of f. Hollow circles are open dots; solid dots are included endpoints.Open in grapher →

The graph "jumps" at x=−1x = -1 and at x=2x = 2. That's allowed. What's not allowed is two filled dots stacked at the same xx-value, because then one input would have two outputs.

Absolute value as a piecewise function

The absolute value of a number is its distance from 00. For a nonnegative number, that's the number itself. For a negative number, it's the opposite of the number (so ∣−5∣=−(−5)=5\lvert -5 \rvert = -(-5) = 5). That description is already a piecewise function:

∣x∣={−x,x<0x,x≥0\lvert x \rvert = \begin{cases} -x, & x < 0 \\ x, & x \ge 0 \end{cases}
The left piece y = −x (x < 0) and the right piece y = x (x ≥ 0) join at the origin to form y = |x|.Open in grapher →

The two pieces are lines with slopes −1-1 and 11 that meet at the vertex (0,0)(0, 0).

Graphing absolute value functions

From the previous lesson, every absolute value function can be written in the transformation form below.

Vertex form of an absolute value function

The graph of f(x)=a∣x−h∣+kf(x) = a\lvert x - h \rvert + k is a V with

  • vertex (h,k)(h, k),
  • slopes aa to the right of the vertex and −a-a to the left,
  • opening up if a>0a > 0 (the vertex is a minimum) and down if a<0a < 0 (the vertex is a maximum).

To graph one, plot the vertex, then use the slope to step off a point on each side.

Worked example: A downward V

Graph f(x)=−2∣x+1∣+4f(x) = -2\lvert x + 1 \rvert + 4. Find its xx-intercepts and range.

The vertex is (−1,4)(-1, 4) and a=−2a = -2, so the V opens down. To the right of the vertex, the slope is −2-2: over 11, down 22, giving (0,2)(0, 2). To the left, the slope is 22 as you move right, so moving left 11 also goes down 22, giving (−2,2)(-2, 2).

xx-intercepts. Set f(x)=0f(x) = 0:

−2∣x+1∣+4=0∣x+1∣=2x+1=2orx+1=−2x=1orx=−3\begin{aligned} -2\lvert x + 1 \rvert + 4 &= 0 \\ \lvert x + 1 \rvert &= 2 \\ x + 1 = 2 \quad &\text{or} \quad x + 1 = -2 \\ x = 1 \quad &\text{or} \quad x = -3 \end{aligned}
y = -2|x + 1| + 4(-1, 4)(-3, 0)(1, 0)Open in grapher →

Range. The highest point is the vertex, so the range is y≤4y \le 4.

Rewriting absolute value without the bars

Sometimes you need an absolute value function as ordinary pieces, for instance to find where it equals a line. Split at the vertex, where the expression inside the bars equals 00.

Worked example: Writing an absolute value function in pieces

Write g(x)=2∣x−3∣−1g(x) = 2\lvert x - 3 \rvert - 1 as a piecewise function with no absolute value bars.

The inside x−3x - 3 is negative when x<3x < 3 and nonnegative when x≥3x \ge 3.

  • For x<3x < 3: ∣x−3∣=−(x−3)\lvert x - 3 \rvert = -(x - 3), so g(x)=−2(x−3)−1=−2x+5g(x) = -2(x - 3) - 1 = -2x + 5.
  • For x≥3x \ge 3: ∣x−3∣=x−3\lvert x - 3 \rvert = x - 3, so g(x)=2(x−3)−1=2x−7g(x) = 2(x - 3) - 1 = 2x - 7.
g(x)={−2x+5,x<32x−7,x≥3g(x) = \begin{cases} -2x + 5, & x < 3 \\ 2x - 7, & x \ge 3 \end{cases}

Both pieces give g(3)=−1g(3) = -1 at the boundary, which matches the vertex (3,−1)(3, -1).

Tip

A quick check for any piecewise form of an absolute value function: both pieces must give the same value at the vertex, since the V is one connected graph. If they don't match, a sign is wrong.

Absolute value inequalities in two variables

An inequality like y≥∣x−1∣−2y \ge \lvert x - 1 \rvert - 2 describes a region. Graph the boundary V (solid for ≥\ge or ≤\le, dashed for >> or <<), then shade the side that works. Test the origin: 0≥∣0−1∣−2=−10 \ge \lvert 0 - 1 \rvert - 2 = -1 is true, so shade the side containing (0,0)(0, 0), which is the inside of the V.

y >= |x - 1| - 2Open in grapher →

Practice

Practice 1

Let f(x)={3x−2,x≤28−x,x>2f(x) = \begin{cases} 3x - 2, & x \le 2 \\ 8 - x, & x > 2 \end{cases}. Find f(2)f(2).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

Using the same function ff from the previous problem, find f(−1)+f(6)f(-1) + f(6).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

What is the vertex of f(x)=−3∣x−4∣+2f(x) = -3\lvert x - 4 \rvert + 2?

Enter a point like (2, -3)

Practice 4

Find both xx-intercepts of f(x)=∣x+2∣−5f(x) = \lvert x + 2 \rvert - 5.

Separate answers with commas, e.g. 2, -5

Practice 5

Which piecewise function is equal to f(x)=∣x+2∣f(x) = \lvert x + 2 \rvert?

Practice 6

Which function is graphed below?

A piecewise graph with an open dot at (1, 3) and a closed dot at (1, 0).Open in grapher →
Practice 7

A shipping company charges $6.00 for a package weighing up to 22 pounds. For heavier packages it charges $6.00 plus $1.50 for each pound over 22. The cost for a package weighing ww pounds is

C(w)={6,0<w≤26+1.5(w−2),w>2C(w) = \begin{cases} 6, & 0 < w \le 2 \\ 6 + 1.5(w - 2), & w > 2 \end{cases}

What is the cost, in dollars, to ship a 77-pound package?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

The graph of f(x)=a∣x−1∣+3f(x) = a\lvert x - 1 \rvert + 3 passes through the point (4,−3)(4, -3). Find aa.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.