topic badge

5.04 Piecewise functions

Lesson

Concept summary

When the pattern or model changes over the domain of a function, we can use a piecewise function to connect the different pieces. A domain is given for each individual function which make up the piecewise function.

A piecewise function with name f open parenthesis x close parenthesis or f of x. The brace { is labelled. There are 3 pieces or functions within the piecewise function, each defined on a separate line. The top function is x minus 3, with domain x is less than  negative 2. The middle function is negative 4, with domain negative 2 is less than or equal to x and x is less than 0. The bottom function is x squared minus 4, with domain x is greater than 0. On each line the function is stated first, followed by a comma, and then the domain as an inequality. Each line is highlighted a different color to emphasise that they are different pieces or functions.

The inequalities for the domains will help us to determine whether the endpoints will be filled or unfilled.

Filled: \bullet for \leq or \geq

Unfilled: \circ for < or >

To graph piecewise functions, it can be helpful to first find all of the endpoints and then determine what the graph will look like between them.

The overall domain of the piecewise function may be all real numbers, or a subset based on the domain constraints.

Worked examples

Example 1

Consider the following piecewise function:

f(x) = \begin{cases} x - 3, & x \lt -2 \\ -4, &-2\leq x \lt 0 \\ x^{2} - 4, & x \gt 0 \end{cases}

a

Sketch the piecewise function.

Approach

We can start by finding the endpoint(s) of each piece - both their coordinates and whether they are filled or unfilled.

Solution

We need to graph each function and limit the graph to the indicated domain.

We can build up the graph of the piecewise function one piece at a time.

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

First piece:

f(x)=x-3 \text{ if } x\lt -2 has one unfilled endpoint at \left(-2,-5\right) because y=x-3 when x=-2, gives y=-5.

This is a line with slope of m=1, so it will also go through the point (-3,-6).

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

Second piece:

f(x)=-4 \text{ if } -2 \leq x \lt 0 has one filled endpoint at \left(-2,-4\right) and an unfilled endpoint at \left(0,-4\right) because all y-coordinates are y=-4 in this piece.

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

Third piece:

f(x)= x^2-4 \text{ if } x \gt 0 has one unfilled endpoint at \left(0,-4\right) because for y=x^2-4 at x=0, we have y=-4.

This is a parabola which has been translated down 4 units, so will be a curve up and to the right.

Reflection

Notice that sometimes the two adjacent pieces connect and other times they do not connect.

b

State the domain and range of the piecewise function.

Approach

The domain is the set of x-values the function is defined for, and the range is the set of y-values the function is defined for. We can identify these from looking at the graph of the piecewise function.

Solution

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

The piecewise function is defined for all values of x except x=0, because of the undefined point at (0,-4). There is also an undefined point at (-2, -5) but since the function is defined at (-2, -4), the piecewise function is defined at x=-2.

Therefore the domain is (-\infty,0)\cup (0,\infty).

The piecewise function is defined for all values of y except -5 \leq y \lt 4, because of the undefined point at (-2,-5) and the gap in the function.

Therefore the range is (-\infty,-5)\cup [4,\infty).

Reflection

We can also use inequalities and set notation to state the domain and range:

Domain: \{x: x \lt 0, x \gt 0\}

Range: \{y: y \lt -5, y \geq 4\}

Example 2

Lizzy goes out for a run. She accelerates from rest up to a desired speed and maintains that speed for some time. Suddenly, she feels exhausted and so she slows down until she's back at rest.

The speed, S, in mi/h after t seconds is given by the following piecewise relationship:

S = \begin{cases} 0.4t, & 0 \leq t \lt 15 \\ 6, & 15 \leq t \lt 100 \\ 36 - 0.3t, & 100 \leq t \leq 120 \end{cases}

a

Sketch the graph of the speed S for time t.

Approach

We can start by finding the endpoints for each piece and since they are all linear functions we can then connect them with line segments.

Solution

For y=0.4t where 0 \leq t <15, the endpoints will be at x=0 and x=15.

\displaystyle y\displaystyle =\displaystyle 0.4tWhen 0 \leq t <15
\displaystyle y\displaystyle =\displaystyle 0.4(0)Substitute x=0
\displaystyle y\displaystyle =\displaystyle 0Endpoint is filled at (0,0)
\displaystyle y\displaystyle =\displaystyle 0.4tWhen 0 \leq t <15
\displaystyle y\displaystyle =\displaystyle 0.4(15)Substitute x=15
\displaystyle y\displaystyle =\displaystyle 6Endpoint is unfilled at (15,6)

For y=6 where 15 \leq t <100, the endpoints will be at x=15 and x=100.

\displaystyle y\displaystyle =\displaystyle 6Endpoint is filled at (15,6)
\displaystyle y\displaystyle =\displaystyle 6Endpoint is unfilled at (100,6)

For y=36-0.3t where 100 \leq t \leq 120, the endpoints will be at x=100 and x=120.

\displaystyle y\displaystyle =\displaystyle 36-0.3tWhen 100 \leq t \leq 120
\displaystyle y\displaystyle =\displaystyle 36-0.3(100)Substitute x=100
\displaystyle y\displaystyle =\displaystyle 6Endpoint is filled at (100,6)
\displaystyle y\displaystyle =\displaystyle 36-0.3tWhen 100 \leq t \leq 120
\displaystyle y\displaystyle =\displaystyle 36-0.3(120)Substitute x=120
\displaystyle y\displaystyle =\displaystyle 0Endpoint is filled at (120,0)

Since the endpoint of one piece connects with the endpoint of the next he graph will appear fully connected.

10
20
30
40
50
60
70
80
90
100
110
120
t
1
2
3
4
5
6
7
8
9
S
b

Find the speed after 10 minutes.

Approach

To find the speed after 10 minutes, we can use the graph or the piecewise function.

Solution

10
20
30
40
50
60
70
80
90
100
110
120
t
1
2
3
4
5
6
7
8
9
S

Using the graph, locate the point where t=10 and determine the value of speed in the S-axis. Based on the graph, the point (10,4) corresponds to time 10 minutes and speed 4 \text{ mi/hr}.

Reflection

We could also find the speed after 10 minutes algebraically.

\displaystyle S(t)\displaystyle =\displaystyle \begin{cases} 0.4t, & 0 \leq t \lt 15 \\ 6, & 15 \leq t \lt 100 \\ 36 - 0.3t, & 100 \leq t \leq 120 \end{cases}Piecewise function
\displaystyle S(t)\displaystyle =\displaystyle 0.4tSince when t=10, 0 \leq t \lt 15
\displaystyle S(10)\displaystyle =\displaystyle 0.4(10)Substitute t=10
\displaystyle S(10)\displaystyle =\displaystyle 4Evaluate the product
c

Determine how long has been Lizzy has been running before she stops.

Approach

She stops when S=0, so we are looking for the t-intercept.

Solution

Based on the graph, Lizzy's final speed is 0 \text{ mi/hr} at t=120.

Lizzy stops running after 120 minutes.

Reflection

We can also see this on the graph:

10
20
30
40
50
60
70
80
90
100
110
120
t
1
2
3
4
5
6
7
8
9
S

Outcomes

M2.F.IF.B.3

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

M2.F.IF.C.6

Graph functions expressed algebraically and show key features of the graph by hand and using technology.*

M2.MP1

Make sense of problems and persevere in solving them.

M2.MP3

Construct viable arguments and critique the reasoning of others.

M2.MP4

Model with mathematics.

M2.MP6

Attend to precision.

M2.MP7

Look for and make use of structure.

M2.MP8

Look for and express regularity in repeated reasoning.

What is Mathspace

About Mathspace