Piecewise Functions
A piecewise function uses different rules for different parts of its domain. Each rule comes with a condition, like x \lt 1 or x \ge 1, that says when to use it. To evaluate a piecewise function, find the piece whose condition fits your input, then use only that rule.
Before this lesson: You should know Function Notation, Domain and Range and Absolute Value Functions.
What a Piecewise Function Looks Like
A piecewise function is written with a large brace. Each row has a rule and a condition:
f(x) = \begin{cases} x + 3, & x \lt 1 \\ 2, & x \ge 1 \end{cases}Read it as: “If x is less than 1, f(x) = x + 3. If x is 1 or more, f(x) = 2.” The conditions do not overlap, so every input uses exactly one rule. That keeps it a function (see relations and functions).
Piecewise functions model real situations where the rule changes, such as tax brackets, shipping rates and phone plans.
Graphing a Piecewise Function
Graph each rule only over its part of the domain. At each boundary, show whether the endpoint is included:
- A closed circle (filled dot) means the endpoint is included: \le or \ge.
- An open circle (hollow dot) means the endpoint is not included: \lt or \gt.
If the two pieces meet at the same point, the graph has no break there and the function is continuous at that point. If they don’t meet, as in the graph above, the graph has a jump.
How to Work with Piecewise Functions
- To evaluate, compare the input with each condition and pick the one piece that fits.
- Substitute into that piece only.
- To graph, draw each rule as if it were alone, but only over its interval.
- At each boundary, find both endpoint values. Use a closed circle for the piece that includes the boundary and an open circle for the one that doesn’t.
Worked Examples
Example 1: Evaluate
Let f(x) = \begin{cases} x + 2, & x \lt 1 \\ 3x, & x \ge 1 \end{cases}. Find f(-3), f(1) and f(4).
- For f(-3): since -3 \lt 1, use x + 2: f(-3) = -3 + 2 = -1
- For f(1): since 1 \ge 1, use 3x: f(1) = 3(1) = 3
- For f(4): since 4 \ge 1, use 3x: f(4) = 3(4) = 12
Answer: f(-3) = -1, f(1) = 3, f(4) = 12. At the boundary x = 1, the condition with “=” decides the piece.
Example 2: Graph, then find the domain and range
Graph g(x) = \begin{cases} x + 3, & x \lt 1 \\ 2, & x \ge 1 \end{cases} and give its domain and range.
- Left piece: the line y = x + 3 for x \lt 1. At x = 1 it would reach 1 + 3 = 4, so draw an open circle at (1, 4) and a ray going down to the left.
- Right piece: the horizontal line y = 2 for x \ge 1. Draw a closed circle at (1, 2) and a ray going right.
- Domain: every x is in one of the pieces, so the domain is (-\infty, \infty).
- Range: the left piece covers every y-value below 4, and the right piece adds 2, which is already below 4. Range: (-\infty, 4).
Answer: The graph is shown above. Domain (-\infty, \infty), range (-\infty, 4). There is a jump at x = 1.
Example 3: Absolute value as a piecewise function
Write f(x) = |x - 2| as a piecewise function.
- When x - 2 \ge 0, the absolute value does nothing: |x - 2| = x - 2.
- Solve the condition: x - 2 \ge 0 means x \ge 2.
- When x - 2 \lt 0, the absolute value takes the opposite: |x - 2| = -(x - 2) = -x + 2.
- That happens when x \lt 2.
Answer: f(x) = \begin{cases} -x + 2, & x \lt 2 \\ x - 2, & x \ge 2 \end{cases}
Example 4: Write a piecewise model
A parking garage charges $3 per hour for the first 2 hours and $2 per hour after that. Write a function for the cost C(h) of parking h hours, and find the cost for 5 hours.
- For 0 \le h \le 2, the cost is $3 per hour: C(h) = 3h.
- For h \gt 2, the first 2 hours cost 3(2) = 6, and each extra hour costs $2: C(h) = 6 + 2(h - 2).
- Write the function: C(h) = \begin{cases} 3h, & 0 \le h \le 2 \\ 6 + 2(h - 2), & h \gt 2 \end{cases}
- For 5 hours, use the second piece: C(5) = 6 + 2(5 - 2)
- Subtract inside: C(5) = 6 + 2(3)
- Multiply, then add: C(5) = 6 + 6 = 12
Answer: Parking for 5 hours costs $12. The two pieces meet at C(2) = 6, so there is no jump.
Example 5: Word problem with a step function
A shipping company charges $5 for packages up to 1 lb, $7 for more than 1 lb up to 2 lb, and $9 for more than 2 lb up to 3 lb. Write the cost function and find the cost of a 2.4 lb package.
- Write each price with its weight interval: S(w) = \begin{cases} 5, & 0 \lt w \le 1 \\ 7, & 1 \lt w \le 2 \\ 9, & 2 \lt w \le 3 \end{cases}
- Find the interval for 2.4: 2 \lt 2.4 \le 3
- Use that piece: S(2.4) = 9
Answer: $9. This is a step function: its graph looks like stairs, with a jump at each whole pound.
Common Mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Using every piece | Finding f(4) by adding 4 + 2 and 3(4) | Use only the one piece whose condition fits. |
| Picking the wrong piece at a boundary | Using x + 2 for f(1) when that piece says x \lt 1 | The piece with \le or \ge includes the boundary. |
| Mixing up open and closed circles | A closed circle at (1, 4) for x \lt 1 | Strict inequalities (\lt, \gt) get open circles. |
| Drawing each rule across the whole graph | Extending y = 2 to the left of 1 | Draw each piece only over its interval. |
| Forgetting the part before the switch | Writing 2(h - 2) for hours after 2 | Add the cost of the first 2 hours: 6 + 2(h - 2). |
Practice Problems
- Let f(x) = \begin{cases} 2x - 1, & x \lt 3 \\ 10 - x, & x \ge 3 \end{cases}. Find f(0), f(3) and f(5).
- Let g(x) = \begin{cases} x^2, & x \le 0 \\ x + 1, & x \gt 0 \end{cases}. Find g(-2), g(0) and g(1).
- Let h(x) = \begin{cases} 4, & x \lt -1 \\ x^2, & -1 \le x \lt 2 \\ 7 - x, & x \ge 2 \end{cases}. Find h(-5), h(-1) and h(2).
- Is the function in problem 1 continuous at x = 3? Explain.
- Find the value of k that makes f(x) = \begin{cases} x + k, & x \lt 2 \\ 3x, & x \ge 2 \end{cases} continuous at x = 2.
- Write f(x) = |x + 1| as a piecewise function.
- Give the domain and range of g(x) = \begin{cases} -1, & x \lt 0 \\ 1, & x \ge 0 \end{cases}.
- A taxi charges $4 for the first mile or less and $2.50 for each additional mile. Write a function for the cost of m miles, and find the cost of a 6-mile ride.
- Use the shipping function S(w) from Example 5. Find the cost for 0.6 lb, 2 lb and 2.01 lb.
- A phone plan costs $30 per month for up to 5 GB of data, plus $10 for each GB over 5. Write the cost function P(g), find P(8), and find how much data costs $55.
Show answers
- 0 \lt 3, so use 2x - 1: f(0) = 2(0) - 1 = -1
3 \ge 3, so use 10 - x: f(3) = 10 - 3 = 7
5 \ge 3: f(5) = 10 - 5 = 5 - -2 \le 0: g(-2) = (-2)^2 = 4
0 \le 0: g(0) = 0^2 = 0
1 \gt 0: g(1) = 1 + 1 = 2 - -5 \lt -1: h(-5) = 4
-1 \le -1 \lt 2: h(-1) = (-1)^2 = 1
2 \ge 2: h(2) = 7 - 2 = 5 - No. The left piece approaches 2(3) - 1 = 5, but f(3) = 7. The values don’t match, so there is a jump at x = 3.
- The pieces must match at x = 2. Right piece: 3(2) = 6
Left piece at 2: 2 + k
Set them equal: 2 + k = 6
Subtract 2 from both sides: k = 4 - x + 1 \ge 0 when x \ge -1: there |x + 1| = x + 1
x + 1 \lt 0 when x \lt -1: there |x + 1| = -x - 1
f(x) = \begin{cases} -x - 1, & x \lt -1 \\ x + 1, & x \ge -1 \end{cases} - Domain: (-\infty, \infty). The outputs are only −1 and 1, so the range is \{-1, 1\}.
- C(m) = \begin{cases} 4, & 0 \lt m \le 1 \\ 4 + 2.5(m - 1), & m \gt 1 \end{cases}
For 6 miles: C(6) = 4 + 2.5(6 - 1)
Subtract: C(6) = 4 + 2.5(5)
Multiply: C(6) = 4 + 12.5
Add: C(6) = 16.5, so $16.50 - 0 \lt 0.6 \le 1: $5
1 \lt 2 \le 2: $7
2 \lt 2.01 \le 3: $9 - P(g) = \begin{cases} 30, & 0 \le g \le 5 \\ 30 + 10(g - 5), & g \gt 5 \end{cases}
P(8) = 30 + 10(8 - 5) = 30 + 10(3) = 30 + 30 = 60, so $60
Set the second piece equal to 55: 30 + 10(g - 5) = 55
Subtract 30 from both sides: 10(g - 5) = 25
Divide both sides by 10: g - 5 = 2.5
Add 5 to both sides: g = 7.5, so 7.5 GB
FAQ
How do you evaluate a piecewise function?
Check which condition the input satisfies, then substitute into that piece only. The other pieces are ignored for that input.
When do you use an open circle on a piecewise graph?
Use an open circle when the endpoint is not included, which happens with \lt or \gt. Use a closed circle with \le or \ge.
What is a step function?
A step function is a piecewise function whose pieces are constant, so the graph looks like stairs. Shipping prices and parking rates are common examples.
How do you know if a piecewise function is continuous?
Check each boundary. If the pieces give the same value there, the graph has no break at that point.
Summary
- A piecewise function uses different rules on different intervals.
- To evaluate, pick the one piece whose condition fits the input.
- Graph each piece only over its interval. Use open circles for \lt/\gt and closed circles for \le/\ge.
- If the pieces meet at a boundary, the function is continuous there. If not, the graph jumps.
- Absolute value functions and step functions are special piecewise functions.
Previous lesson: Absolute Value Functions
Next lesson: Function Operations
Back to the Algebra 2 Index