Writing a piecewise rule from a graph
You have the graph of a function whose rule changes partway along. How do you get the formulas back, and say exactly which inputs each one is in charge of?
Where you are 4 in Piecewise functions
When you reach for it
Graphing a piecewise function goes from the rule to the picture. This lesson goes the other way. You have a graph made of pieces, perhaps a record of a machine’s speed or a sketch someone else drew, and you want its rule: a formula for each piece and the inputs that piece covers. With the rule in hand you can evaluate the function at inputs between grid lines, where reading the picture is only a guess.
The procedure
Take the graph of f below.
Find the boundaries. Scan from left to right for every input where the graph changes: a dot, a break or a corner. Here there is one, x = 1. Each stretch between boundaries is one piece, and each piece gets one line of the rule.
A formula for each piece. Each piece here is straight, so it is part of a line, and a line is fixed by its slope and one point. Pick two points where the piece crosses grid corners, so the coordinates are exact, and find the slope as rise over run (The slope formula and the four kinds of slope). The left piece passes through (0, 1) and (1, 3), so its slope is \displaystyle \frac{3 - 1}{1 - 0} = 2. It crosses the y-axis at 1, so its formula is y = 2x + 1 (Slope-intercept form). The right piece passes through (1, 0) and (3, -2), slope \displaystyle \frac{-2 - 0}{3 - 1} = -1. It never reaches the y-axis, so use point and slope instead: y - 0 = -1(x - 1), so y = 1 - x. An open dot may serve as one of the two points. It is not on the graph, but it is on the line the piece lies on, and the formula describes that line.
A horizontal piece has slope 0, so its formula is a constant: y = c, where c is its height.
The interval each piece covers. Read the piece’s shadow on the x-axis, as in Domain and range from a graph. An arrow means no end on that side. The left piece covers every input up to 1; the right piece covers the inputs from 1 onwards.
Who owns the boundary. The dots decide. A closed dot is on the graph, so its input belongs to that piece, written with \le or \ge. An open dot is not on the graph, so its piece leaves the input out, written with < or >. The closed dot (1, 3) gives the left piece x \le 1, and the open dot (1, 0) gives the right piece x > 1:
Each boundary input goes in exactly one condition, unless both formulas give the same output there, because the Testing graphs and equations for functions allows only one point above each input. Where two pieces meet at a corner with no dot drawn, the corner is on the graph and both formulas give its height, so either piece may take it (Example 3).
Check the rule. Evaluate the rule at an input inside each piece and at each boundary, and compare with the graph. Inside, f(0) = 1 and f(3) = 1 - 3 = -2, both on the graph. At the boundary, 1 satisfies only x \le 1, so f(1) = 2(1) + 1 = 3, the height of the closed dot. A wrong slope or intercept shows up at the inside points; a wrong inequality shows up at the boundary.
Worked examples
Two rays and a jump
Write a rule for the function g graphed below.
The graph breaks at x = 2, its only boundary.
The left piece passes through (0, -1) and the open dot (2, 3), so its slope is \displaystyle \frac{3 - (-1)}{2 - 0} = 2, and it crosses the y-axis at -1: y = 2x - 1. It runs to the left without end, and its dot at x = 2 is open, so its condition is x < 2.
The right piece passes through the closed dot (2, 1) and through (4, 2), slope \displaystyle \frac{2 - 1}{4 - 2} = \frac{1}{2}. From the point (2, 1), \displaystyle y - 1 = \frac{1}{2}(x - 2), so \displaystyle y = \frac{1}{2}x. The closed dot gives x \ge 2.
Check: g(0) = -1 and g(4) = 2 are on the graph, and g(2) uses the second line, \displaystyle \frac{1}{2}(2) = 1, the closed dot.
A constant piece between two slanted ones
Write a rule for h, and give its domain.
The boundaries are x = -2 and x = 2, and the graph has ends at x = -4 and x = 5. So there are three pieces, each with two ends and no arrows, and each condition has two ends too.
First piece: from the closed dot (-4, -3) to the open dot (-2, 1), slope \displaystyle \frac{1 - (-3)}{-2 - (-4)} = 2. From (-2, 1), y - 1 = 2(x + 2), so y = 2x + 5, for -4 \le x < -2.
Second piece: flat at height 3 between the closed dots (-2, 3) and (2, 3). Its slope is 0, so its formula is the constant 3, for -2 \le x \le 2.
Third piece: from the open dot (2, 2) to the closed dot (5, -1), slope \displaystyle \frac{-1 - 2}{5 - 2} = -1. From (2, 2), y - 2 = -(x - 2), so y = 4 - x, for 2 < x \le 5.
Check: h(-3) = -1, h(0) = 3 and h(4) = 0 are on the graph. The inputs -2 and 2 each satisfy only the middle condition, and h(-2) = h(2) = 3, the two closed dots. The domain is the conditions put together, [-4, 5].
Pieces that meet at a corner
Write a rule for k.
The only boundary is the corner at (1, -2).
The left piece passes through (0, 1) and (1, -2): slope -3, intercept 1, so y = 1 - 3x.
The right piece passes through (1, -2) and (3, -1), slope \displaystyle \frac{-1 - (-2)}{3 - 1} = \frac{1}{2}. From (1, -2), \displaystyle y + 2 = \frac{1}{2}(x - 1), so \displaystyle y = \frac{1}{2}x - \frac{5}{2}. The intercept \displaystyle -\frac{5}{2} falls between grid lines, which is why point and slope beats reading it off.
No dot is drawn at the corner, so (1, -2) is on the graph, and both formulas give -2 there: 1 - 3(1) = -2 and \displaystyle \frac{1}{2} - \frac{5}{2} = -2. Either piece may own the boundary. Giving it to the left one,
The rule with x < 1 and x \ge 1 describes the same function, and so does x \le 1 with x \ge 1, since the shared input gets one output either way. Leaving 1 out of both conditions would be wrong: it would punch a hole at the corner.
Check: k(-1) = 4 and k(3) = -1 match the graph, and k(1) = -2 is the corner.
The V of the absolute value
Write a two-piece rule for the graph of y = |x|.
The graph of the absolute value is a V with its corner at the origin.
The right arm passes through (0, 0) and (2, 2): slope 1, intercept 0, so y = x. The left arm passes through (0, 0) and (-2, 2), slope \displaystyle \frac{2 - 0}{-2 - 0} = -1, so y = -x. The corner is on the graph and both formulas give 0 there; giving it to the right arm,
On the left arm x is negative, so -x is positive: |-3| = -(-3) = 3. Reading the graph has given back the definition of absolute value, one line for each arm.
A delivery robot’s speed
A delivery robot’s speed v, in meters per second, t seconds after it sets off, is graphed below. Write a rule for v, and say what each piece means.
The graph has corners at t = 4 and t = 10 and ends at t = 0 and t = 14.
From (0, 0) to (4, 2) the slope is \displaystyle \frac{2}{4} = \frac{1}{2} and the intercept is 0, so \displaystyle v = \frac{1}{2}t: the robot gains half a meter per second every second.
From (4, 2) to (10, 2) the piece is flat, v = 2: a steady 2 meters per second.
From (10, 2) to (14, 0) the slope is \displaystyle \frac{0 - 2}{14 - 10} = -\frac{1}{2}. From (10, 2), \displaystyle v - 2 = -\frac{1}{2}(t - 10), so \displaystyle v = 7 - \frac{1}{2}t. The 7 is where the whole line would meet the speed axis; the robot never moved at 7 meters per second, because this piece covers only t from 10 to 14. Writing it as \displaystyle 2 - \frac{1}{2}(t - 10) keeps the meaning in view: 2 meters per second at t = 10, losing half a meter per second each second after.
The graph joins at both corners, so each corner may go to either side. Giving each to the earlier piece,
Check: v(2) = 1 and v(12) = 7 - 6 = 1, half way up and half way down, as on the graph; v(4) = 2, v(10) = 2, and v(14) = 0, the robot at rest. The domain [0, 14] is the time the graph records.
Testing a proposed rule against its graph
The rule below is proposed for the function graphed under it. Test it at a point inside each piece and at the boundary, and change whatever does not match the graph.
Inside the left piece, p(-2) = 1 - (-2) = 3, and the graph passes through (-2, 3). That line of the rule matches the graph.
Inside the right piece, p(2) = 3 + 2 = 5, but the graph passes through (2, 1). The slope agrees with the graph, \displaystyle \frac{1 - (-2)}{2 - 0} = \frac{3}{2}, so the proposed line is parallel to the piece and only its height differs. The piece meets the y-axis at the closed dot (0, -2), so its intercept is -2 and its formula is \displaystyle y = \frac{3}{2}x - 2.
At the boundary, 0 satisfies -3 \le x \le 0, so the proposed rule gives p(0) = 1. On the graph (0, 1) is an open dot and the closed dot is (0, -2), so 0 belongs to the right piece. With both changes the rule is
Check again: p(-2) = 3, p(2) = 1, p(0) = -2, and p(-3) = 4, the closed dot at the left end. The inside points tested the formulas and the boundary tested the inequalities; neither test alone finds both differences.
Boundaries
- Exact formulas need exact points. Take slopes from points where a piece crosses grid corners; a point read between grid lines gives an estimate, not a rule.
- The method here is for straight pieces. A curved piece needs the formula of its own family, such as a parabola’s.
- The rule is only as complete as the graph. A piece that stops at a dot covers nothing past it, and inputs under no piece are outside the domain.
- An input may sit in two conditions only if the formulas agree there. Two closed dots stacked above one input mean the graph is not a function, and no rule describes it.
Where this goes next
Graphs of real rules that change at a threshold, such as charges by weight, are read the same way in Piecewise functions in context. A graph made entirely of flat steps gives the Step functions and the greatest integer function. Every shifted or stretched V from Transforming the absolute value graph can be written as two lines, as in Example 4. Whether a graph joins, jumps or has a hole at a boundary is studied in Continuous graphs, jumps and holes.
Exercises
One piece at a time
Write the formula and the condition for each piece.
- A segment from a closed dot at (-1, 2) to an open dot at (3, 10).
- A ray that starts at an open dot at (2, -1) and runs to the right through (6, 1).
- A horizontal segment from an open dot at (-4, -3) to a closed dot at (1, -3).
- A ray that comes from the left through (-3, -1) and ends at a closed dot at (0, 5).
Whole graphs
Write a rule for each graph, and check it at each boundary.
- Graph A.
- Graph B.
- Graph C.
- Graph D, and give its domain.
- Graph E.
- Graph F.
Check the rule
- A rule proposed for graph A is -2x - 4 if x < -1, and \displaystyle \frac{1}{2}x + \frac{3}{2} if x \ge -1. Which test fails, and what change makes the rule match the graph?
- A rule proposed for graph C is 1 - x if x \le 2, and 2x - 5 if x \ge 2. Both conditions include 2. Is it still a rule for graph C?
- A rule proposed for graph D is \displaystyle -\frac{1}{2}x if -4 \le x \le 0, and 2x - 3 if x > 2. Evaluate it at x = 5 and say what must change.
In context
- On a second run, the robot of Example 5 speeds up steadily from rest to 3 meters per second in 2 seconds, holds that speed for 6 seconds, then slows steadily to a stop in 3 seconds. Write a rule for its speed, and check it at each corner.
Reasoning
- Using the vertical line test, explain why no rule for graph A can have both conditions include -1, while a rule for graph C may have both conditions include 2.
- Show that your rule for graph F equals |x + 2| + 1, by treating x \ge -2 and x < -2 separately.
- Two straight pieces meet at a corner. Explain why the rule still needs two formulas, and why it does not matter which condition gets the corner’s input.
Answers
- y = 2x + 4 for -1 \le x < 3. Slope \displaystyle \frac{10 - 2}{3 - (-1)} = 2, and y - 2 = 2(x + 1).
- \displaystyle y = \frac{1}{2}x - 2 for x > 2. Slope \displaystyle \frac{1 - (-1)}{6 - 2} = \frac{1}{2}, and \displaystyle y + 1 = \frac{1}{2}(x - 2).
- y = -3 for -4 < x \le 1.
- y = 2x + 5 for x \le 0. Slope \displaystyle \frac{5 - (-1)}{0 - (-3)} = 2, intercept 5.
- -2x - 4 if x \le -1; \displaystyle \frac{1}{2}x + \frac{3}{2} if x > -1. Left through (-3, 2) and (-1, -2), slope -2; right through (-1, 1) and (3, 3), slope \displaystyle \frac{1}{2}. At -1 the rule gives -2(-1) - 4 = -2, the closed dot.
- 4 if x < -2; \displaystyle \frac{1}{2}x + 1 if -2 \le x \le 4. The segment passes through (-2, 0) and (2, 2), slope \displaystyle \frac{1}{2}, intercept 1. At -2 the rule gives 0, the closed dot.
- 1 - x if x < 2; 2x - 5 if x \ge 2 (or \le on the first line and > on the second). Left through (0, 1) and (2, -1); right through (2, -1) and (4, 3), slope 2. At the corner both give -1.
- \displaystyle -\frac{1}{2}x if -4 \le x \le 0; 2x - 3 if 2 < x \le 4. Domain [-4, 0] \cup (2, 4]. Right piece through (2, 1) and (4, 5), slope 2; at 4 it gives 5, the closed dot.
- x - 1 if x \ne 2; 4 if x = 2. The line passes through (0, -1) and (1, 0), slope 1. At 2 it would give 1, the open dot; the closed dot is at height 4.
- -x - 1 if x < -2; x + 3 if x \ge -2. Left through (-4, 3) and (-2, 1), slope -1; right through (-2, 1) and (0, 3). At the corner both give 1.
- The boundary test. The rule gives \displaystyle \frac{1}{2}(-1) + \frac{3}{2} = 1 at x = -1, the open dot, but the closed dot is (-1, -2). Swap the inequalities to x \le -1 and x > -1.
- Yes. At 2 both formulas give -1, so the input 2 still has one output.
- It gives 2(5) - 3 = 7, but graph D has nothing above 5: the piece ends at the closed dot (4, 5). The condition needs a right end, 2 < x \le 4.
- \displaystyle \frac{3}{2}t if 0 \le t \le 2; 3 if 2 < t \le 8; 11 - t if 8 < t \le 11. The last piece has slope \displaystyle \frac{0 - 3}{11 - 8} = -1 and v - 3 = -(t - 8). Corners: v(2) = 3, v(8) = 3, v(11) = 0.
- At -1 the formulas of graph A give -2 and 1. If both conditions included -1, the input would have two outputs, two points in one column, which the vertical line test forbids. In graph C both formulas give -1 at 2, so including 2 twice still gives one point.
- If x \ge -2, then x + 2 \ge 0, so |x + 2| + 1 = x + 2 + 1 = x + 3. If x < -2, then x + 2 < 0, so |x + 2| + 1 = -(x + 2) + 1 = -x - 1. These are the two pieces.
- A line has one slope, and the pieces have different slopes, so no single linear formula fits both. At the corner both formulas give the corner’s height, so whichever condition holds that input, its output and the graph are the same.