topic badge

3.08 Piecewise functions

Introduction

Other types of linear functions that are not strictly increasing, decreasing, or constant may be needed to model a context. In this lesson, we will use what we know about graphing linear functions and key features of graphs to extend to new types of function: piecewise functions, absolute value functions, and step funcitons.

Linear piecewise functions

Sometimes more than one linear equation is needed to create a linear model for a given situation. Piecewise graphs are formed by two or more functions on restricted domains.

In a piecewise-defined function, a domain is given for each equation.

Consider the following linear piecewise function: f(x) = \begin{cases} x+2, & x \leq 0 \\ \dfrac{1}{2}x+5, & 0<x<3 \\ -x-1, & x \geq 3 \end{cases}

-9
-8
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-9
-8
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
y

The line for f\left(x\right)=x+2 is drawn for x-values less than and including 0, the line for f(x)=\dfrac{1}{2}x+5 is only drawn for x-values between 0 and 3, and the line for f(x)=-x-1 is drawn from x-values greater than and including 3.

The circles on the graph have the same meaning as inequalities on the number line:

  • An unfilled circle does not include an endpoint in the function.
  • A filled circle includes an endpoint in the function.

Examples

Example 1

Consider the following linear piecewise function: f(x) = \begin{cases} \dfrac{3}{4}x-2, & x < -2 \\ 1, & -2 \leq x < 4 \\ x + 3, & x \geq 4 \end{cases}

a

Evaluate the function at f(-4), f(-2), f(0), and f(4).

Worked Solution
Create a strategy

For each value of x, we can determine which function from the piecewise function to evaluate based on the given domain.

Apply the idea

Since x=-4 is in the domain of \dfrac{3}{4}x-2, f(-4)=\dfrac{3}{4}(-4)-2=-3-2=-5.

Since x=-2 is in the domain of 1, f(-2)=1.

Since x=0 is in the domain of 1, f(0)=1.

Since x=4 is in the domain of x+3, f(4)=(4)+3=7.

b

Graph the piecewise function.

Worked Solution
Create a strategy

The three functions have their own place on the coordinate plane, so we can draw each function and erase the part of the function in the domain that the line does not belong to.

Apply the idea
-9
-8
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-9
-8
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
y
Reflect and check

Note that this is still considered a function because it passes the vertical line test, or rather, each input has a single unique output.

c

Describe the key features of the function graphed in part (b).

Worked Solution
Create a strategy

Recall that key features may include domain, range, intercepts, minimum and maximum points, rate of change, increasing and decreasing intervals, positive and negative intervals, and end behavior.

Apply the idea

Domain: \left(-\infty, \infty\right)

Range: \left(-\infty, -3.5\right) \cup \left[1\right] \cup \left[7, \infty\right)

y-intercept: \left(0,1\right)

Increasing on \left(-\infty, -2\right) and \left(4, \infty\right)

Negative interval: \left(-\infty, -2\right)

Positive interval: \left[-2,\infty\right)

End behavior: As x \to -\infty, y \to -\infty and as x \to \infty, y \to \infty

Example 2

Write the piecewise-defined function based on the graph shown:

-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
y
Worked Solution
Create a strategy

By covering up each part of the graph or imagining that we can extend each line, we can find the y-intercept and count the rise and run for each line to determine the slope.

Apply the idea
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
y
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
y
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
x
-7
-6
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
y

The piecewise-defined function for the given graph is

f(x) = \begin{cases} 4x+3, & x < 0 \\ -\dfrac{1}{2}x+3, & 0 \leq x \leq 4 \\ x - 3, & 4 < x < 9 \end{cases}

Reflect and check

Since the functions have an overlap, the function assigned for each endpoint could have been different in the solution. If the problem were given in context, it may be clearer which endpoint is included with which function. Another possible piecewise-defined function could be

f\left(x\right) = \begin{cases} 4x+3, & x \leq 0 \\ -\dfrac{1}{2}x+3, & 0 < x < 4 \\ x - 3, & 4 \leq x < 9 \end{cases}

Idea summary

The domain of a piecewise function is visible in both the piecewise-defined function and the graph itself.

Absolute value functions

An absolute value function is a function that contains a variable expression inside absolute value bars; a function of the form f\left(x\right) = a\left|x - h\right| + k, where a, h and k are constants.

Let's consider the absolute value function f\left(x\right)=\left|x\right|. This looks similar to the linear function f\left(x\right)=x but with absolute value signs. We know that f\left(x\right)=x represents a straight line through the origin on the coordinate plane.

Recall that absolute value represents the distance from zero, which is always positive. So, outputs for negative input values will be positive, as shown in the table and on the diagram below. Notice that this occurs at the x-intercept of the graph of f\left(x\right)=x.

Table of values:

x-2-1012
f\left(x\right)=\left|x\right|21012

Graph:

-4
-3
-2
-1
1
2
3
4
x
-4
-3
-2
-1
1
2
3
4
f(x)

We can think of absolute value functions as being defined by two functions: one for values of x that would make the original function positive and another for values of x that make the original function negative.

So, f\left(x\right)=\left|x\right| can be redefined as:

f(x)= \begin{cases} -x, &x<0 \\x, &x \geq 0 \end{cases}

-4
-3
-2
-1
1
2
3
4
-4
-3
-2
-1
1
2
3
4

Examples

Example 3

Consider the function f\left(x\right) = \left|3x - 6 \right|.

x012345
f\left(x\right)
a

Complete the table of values for this function.

Worked Solution
Create a strategy

We can substitute each value of x into the original equation and evaluate the right hand side to find the value of f\left(x\right).

Apply the idea

f\left(0\right) = \left|3\left(0\right) - 6 \right|=\left|0 - 6 \right|=\left|- 6 \right|=6

f\left(1\right) = \left|3\left(1\right) - 6 \right|=\left|3 - 6 \right|=\left|- 3 \right|=3

f\left(2\right) = \left|3\left(2\right) - 6 \right|=\left|6 - 6 \right|=\left|0 \right|=0

f\left(3\right) = \left|3\left(3\right) - 6 \right|=\left|9 - 6 \right|=\left|3 \right|=3

f\left(4\right) = \left|3\left(4\right) - 6 \right|=\left|12 - 6 \right|=\left| 6 \right|=6

f\left(5\right) = \left|3\left(5\right) - 6 \right|=\left|15 - 6 \right|=\left|9 \right|=9

So the completed table is:

x012345
f\left(x\right)630369
b

State the minimum and the y-intercept of the function.

Worked Solution
Create a strategy

These key features can be identified by using the completed table of values.

Apply the idea

The minimum of the function is also the x-intercept, at \left(2,0\right).

The y-intercept of the function from the table occurs when x=0, at \left(0,6\right).

c

Sketch a graph of the function.

Worked Solution
Apply the idea
-2
-1
1
2
3
4
5
6
7
8
x
-2
-1
1
2
3
4
5
6
7
8
y
Reflect and check

We can see the key features we identified from the table in part (b) on the graph shown.

d

Write the absolute value function as a piecewise-defined function.

Worked Solution
Create a strategy

The minimum point on the graph gives us information about where the two functions switch.

Apply the idea

For values of x less than 2, the graph is decreasing. For values of x greater than 2, the graph is increasing.

The piecewise-defined absolute value function is

f(x) = \begin{cases} -(3x-6), & x < 2 \\ 3x-6, & x \geq 2 \end{cases}

Reflect and check

We can draw the piecewise-defined function on a coordinate grid with the domain constraints to confirm that the absolute value function matches.

Idea summary

Absolute value functions can be rewritten as piecewise-defined functions made up of two linear functions that split at the vertex.

f\left(x\right)=\left|x\right| can be redefined as:

f\left(x\right)= \begin{cases} -x, x<0 \\x, x \geq 0 \end{cases}

Step functions

A step graph is a type of function that takes constant values over intervals on the x-axis. Because of this, the graph doesn't change gradually but has distinct "steps".

-4
-3
-2
-1
1
2
3
4
-4
-3
-2
-1
1
2
3
4

The graph shows an example of a step function.

The endpoints on the graph provide information about the value of the function at that point, depending on if the circle is filled or unfilled.

At x=-3 in the domain, two endpoints, \left(-3,-3\right) and \left(-3,-2\right), are graphed. Since \left(-3,-2\right) has a filled circle at this point, the value of the function when x=-3 is -2, and not -3.

Examples

Example 4

A parking lot charges the following fees for the first hour of parking:

Parking Lot Charges
15
30
45
60
\text{Time (minutes)}
4
8
\text{Parking fee (dollars)}
a

If a car is in the lot for 20 minutes, how much will they be charged?

Worked Solution
Create a strategy

By finding 20 minutes on the x-axis and reading the graph at that point, we can determine the charge for 20 minutes.

Apply the idea

At 20 minutes, the cost to park in the lot is \$8.

b

Explain the meaning of the y-intercept in context.

Worked Solution
Apply the idea

The y-intercept is at \left(0,4\right), meaning that as soon as a person enters the parking lot, they are charged the initial fee of \$4 to park, even if they leave within 0 minutes.

c

Explain why a person who parks for 15 minutes is not charged \$4 for parking.

Worked Solution
Apply the idea

Although 15 minutes is shown in two points on the graph, the unfilled circle on the step that indicates the parking fee is \$4 means that 15 minutes is not included in the first time interval for parking. Instead, the person must pay \$8 to park for 15 minutes.

d

If \$24 is charged for parking from 1 hour up to 3 hours and \$34 is charged for parking from 3 hours up to 4 hours, draw the rest of the graph that displays charges for up to 4 hours of parking.

Worked Solution
Create a strategy

The wording of the problem and the structure of the step graph shown informs us of the times that are included or excluded from the fee structure.

Apply the idea

Graph a horizontal line from 60 minutes to 180 minutes with a filled circle at 1 hour and an unfilled circle at 3 hours. Then, graph a horizontal line from 180 minutes to 240 minutes with a filled circle at 3 hours and an unfilled circle at 4 hours

Parking Lot Charges
30
60
90
120
150
180
210
240
\text{Time (minutes)}
4
8
12
16
20
24
28
32
36
\text{Parking fee (dollars)}

Example 5

Create a step graph for the charge for sending parcels, where the vertical axis is in dollars:

Maximum weight (lbs.)Charge per item
0.5\$2.50
3\$4.25
5\$7.75
Worked Solution
Create a strategy

We need to determine the right interval for the charge. A parcel cannot weigh equal to or less than 0 pounds or cost equal to or less than \$0, so the axes should start at zero.

Apply the idea
Mailing Parcels
1
2
3
4
5
\text{Weight (lbs.)}
1
2
3
4
5
6
7
8
\text{Charge}
Idea summary

The value of a step function will be the same for an interval of x, giving it the look of a staircase.

Outcomes

A.CED.A.2

Create equations in two or more variables to represent relationships between quantities; graph equations on coordinate axes with labels and scales.

F.IF.B.4

For a function that models a relationship between two quantities, interpret key features of graphs and tables in terms of the quantities, and sketch graphs showing key features given a verbal description of the relationship. Key features include: intercepts; intervals where the function is increasing, decreasing, positive, or negative; relative maximums and minimums; symmetries; end behavior; and periodicity.

F.IF.C.7

Graph functions expressed symbolically and show key features of the graph, by hand in simple cases and using technology for more complicated cases.

F.IF.C.7.B

Graph square root, cube root, and piecewise-defined functions, including step functions and absolute value functions.

F.IF.C.9

Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions).

What is Mathspace

About Mathspace