Piecewise Functions

Learning goals

  • Evaluate a piecewise function by choosing the piece whose condition holds
  • Graph each piece over its own interval with a closed or open dot at the boundary
  • Compare the two boundary heights to tell a jump from a join
  • Find the domain and range from each piece's restricted interval
  • Recognize absolute value, floor, and ceiling as piecewise functions from earlier lessons

What a piecewise function is

Take the parking garage from the introduction: 55 dollars for a stay of one hour or less, 88 dollars for anything longer. Call the charge C(h)C(h) for a stay of hh hours. There are two rules, and each one owns its own share of the possible stays:

C(h)={5if 0<h≤1,8if h>1.C(h) = \begin{cases} 5 & \text{if } 0 < h \le 1, \\ 8 & \text{if } h > 1. \end{cases}

Every value of CC is in dollars. To use it, decide which condition your stay satisfies, then read off that piece’s charge.

Stay hhCondition trueCharge C(h)C(h)
0.50.5 hour0<h≤10 < h \le 155
11 hour0<h≤10 < h \le 155
2.52.5 hoursh>1h > 188

A piecewise function is defined by two or more formulas, called pieces, each paired with a condition that says which inputs it governs. The pieces are collected under one large brace, as in CC above. A larger piecewise function works the same way with more pieces. Here is one with three:

f(x)={x+3if x<−1,x2if −1≤x≤2,8−xif x>2.f(x) = \begin{cases} x + 3 & \text{if } x < -1, \\ x^2 & \text{if } -1 \le x \le 2, \\ 8 - x & \text{if } x > 2. \end{cases}

Read the conditions first, then use the matching formula. For x=3x=3, only x>2x>2 holds, so f(3)=8−3=5f(3)=8-3=5. For x=0x=0, the middle condition holds, so f(0)=02=0f(0)=0^2=0. Substituting into another formula would give the wrong output.

A boundary is an input where one interval ends and the next begins, such as −1-1 or 22 here. At a boundary, check which inequality includes the “or equal to” part. The input −1-1 fails x<−1x<-1 but satisfies −1≤x≤2-1\le x\le2, so it uses the middle piece: f(−1)=(−1)2=1f(-1)=(-1)^2=1. Throughout this lesson, the conditions give each input in the intended domain exactly one piece. This avoids conflicting outputs. Overlapping conditions can still define a function if their formulas agree wherever they overlap.

For example, suppose x+1x+1 is used for x≤1x\le1 and 44 for x≥1x\ge1. Both conditions claim x=1x=1, where the outputs 22 and 44 differ, so this rule is not a function. If the second formula were 22 instead, both would give 22 at x=1x=1, and that overlap would be harmless.

Worked example 1 Evaluate a three-piece function

Use the function

f(x)={x+3if x<−1,x2if −1≤x≤2,8−xif x>2,f(x) = \begin{cases} x + 3 & \text{if } x < -1, \\ x^2 & \text{if } -1 \le x \le 2, \\ 8 - x & \text{if } x > 2, \end{cases}

and find f(−4)f(-4), f(−1)f(-1), f(2)f(2), and f(5)f(5). For each input, name the condition first.

The input −4-4 satisfies x<−1x < -1, so the first piece applies and f(−4)=−4+3=−1f(-4) = -4 + 3 = -1.

The input −1-1 is a boundary. It fails x<−1x < -1 but satisfies −1≤x≤2-1 \le x \le 2, so the middle piece owns it and f(−1)=(−1)2=1f(-1) = (-1)^2 = 1.

The input 22 is the other boundary. It satisfies −1≤x≤2-1 \le x \le 2 (again by the “or equal to”), so the middle piece applies and f(2)=22=4f(2) = 2^2 = 4.

The input 55 satisfies x>2x > 2, so the third piece applies and f(5)=8−5=3f(5) = 8 - 5 = 3.

f(−4)=−1,f(−1)=1,f(2)=4,f(5)=3.f(-4) = -1, \quad f(-1) = 1, \quad f(2) = 4, \quad f(5) = 3.

Both boundaries went to the middle piece, because both of its inequalities carry the “or equal to.”

Check your understanding

Find g(3)g(3) for the function

g(x)={2x+1if x<3,4−xif x≥3.g(x) = \begin{cases} 2x + 1 & \text{if } x < 3, \\ 4 - x & \text{if } x \ge 3. \end{cases}

Answer choices

Graphing a piecewise function

To graph a piecewise function, graph each piece on its own interval and nowhere else. For the running ff, you draw the line y=x+3y = x + 3 only to the left of −1-1, and the parabola y=x2y = x^2 only from −1-1 to 22. The line y=8−xy = 8 - x is drawn only to the right of 22. What is new is deciding what to draw at the ends of each interval, and the inequality signs tell you how.

For the line and polynomial pieces here, substitute the boundary input to locate the endpoint. Use a closed dot if the condition includes that input (≤\le or ≥\ge), and an open dot if it excludes it (<< or >>). A filled dot belongs to the graph; a hollow dot only shows where that piece approaches. Another piece may include the same point.

Watch how that plays out on a simple two-piece function:

g(x)={x+1if x≤1,4if x>1.g(x) = \begin{cases} x + 1 & \text{if } x \le 1, \\ 4 & \text{if } x > 1. \end{cases}

The first piece is the line y=x+1y = x + 1 drawn up to x=1x = 1. Its condition includes the boundary (x≤1x \le 1), so it truly reaches the point (1,2)(1, 2), drawn as a closed dot. The second piece is the constant y=4y = 4 drawn for every input past 11. Its condition excludes the boundary (x>1x > 1), so at x=1x = 1 it stops just short with an open dot at (1,4)(1, 4). Between those two dots the graph leaps straight from height 22 up to height 44 without passing through the values in between. That leap is a jump.

A piecewise function with a jump at x equals 1The piece y equals x plus 1 reaches a closed dot at 1 comma 2, and the piece y equals 4 begins at an open dot at 1 comma 4, so the graph leaps from height 2 to height 4 at the boundary.xy-4-3-2-1123454321-1-2-30y = x + 1y = 4(1, 2)(1, 4)jump
A piecewise function that jumps. The line piece y equals x plus 1 runs up to x equals 1, where its condition includes the boundary, so it reaches the point (1, 2) with a closed (filled) dot. The constant piece y equals 4 governs every input past 1, so at x equals 1 it stops just short with an open (hollow) dot at (1, 4). The two pieces reach different heights at x equals 1, height 2 and height 4, so the graph jumps and cannot be drawn without lifting the pen.

For gg, the boundary formulas give 1+1=21+1=2 and 44. The two heights differ, so there is a jump at x=1x=1. Do not draw a vertical segment between them: that would assign several outputs to the same input.

For adjacent line, constant, or polynomial pieces, compare their values at the boundary. Each piece approaches the value its formula gives there. If the heights agree and one piece includes that point, the graph connects. If the heights differ, it jumps. This test is enough for the pieces used here.

The conditions still matter. If both pieces exclude the boundary, even matching heights leave a point missing. Also, if a different kind of formula is undefined at the boundary, you cannot use substitution to decide how its graph behaves there. Do not assume that every boundary is a jump or a join.

Compare gg with a function whose pieces agree at the boundary:

h(x)={2xif x<1,x+1if x≥1.h(x) = \begin{cases} 2x & \text{if } x < 1, \\ x + 1 & \text{if } x \ge 1. \end{cases}

At x=1x = 1 the first piece heads toward 2⋅1=22 \cdot 1 = 2 and the second piece sits at 1+1=21 + 1 = 2. The excluded point from the left piece and the included point from the right piece are both (1,2)(1, 2). Because they are the same point, they merge into one filled dot and the graph has no gap. It still turns a sharp corner, because the slopes differ (22 on the left, 11 on the right), but a corner is not a jump. You can trace the whole graph without lifting the pen.

A piecewise function that connects at x equals 1The piece y equals 2x and the piece y equals x plus 1 both reach height 2 at x equals 1, so they meet at a single filled dot at 1 comma 2 with a corner and no jump.xy-2-1123454321-1-20y = 2xy = x + 1(1, 2)
A piecewise function that connects. The piece y equals 2x runs up to the boundary x equals 1, and the piece y equals x plus 1 begins there. Both pieces reach height 2 at x equals 1, so the hollow endpoint of the left piece lands on the filled endpoint of the right piece and they merge into a single closed dot at (1, 2). The graph has a corner because the slopes differ, but no jump, so it can be drawn without lifting the pen.

Worked example 2 Describe the graph at each boundary

Sketch the shape of

p(x)={−2if x<0,x−2if 0≤x≤3,3if x>3,p(x) = \begin{cases} -2 & \text{if } x < 0, \\ x - 2 & \text{if } 0 \le x \le 3, \\ 3 & \text{if } x > 3, \end{cases}

reading off the dots and deciding jump or connect at each boundary.

At x=0x = 0, the left piece is the constant −2-2, which excludes 00 (its condition is x<0x < 0), so it gives an open dot at (0,−2)(0, -2). The middle piece includes 00 and gives 0−2=−20 - 2 = -2, a closed dot at (0,−2)(0, -2). Both pieces reach height −2-2, so the dots land on the same point and the graph connects at x=0x = 0.

At x=3x = 3, the middle piece includes 33 and gives 3−2=13 - 2 = 1, a closed dot at (3,1)(3, 1). The right piece is the constant 33, which excludes 33 (its condition is x>3x > 3), so it gives an open dot at (3,3)(3, 3). The heights 11 and 33 differ, so the graph jumps at x=3x = 3.

connects at x=0,jumps at x=3.\text{connects at } x = 0, \qquad \text{jumps at } x = 3.

So pp runs flat at height −2-2, then rises along a line of slope 11 from (0,−2)(0, -2) up to the closed dot (3,1)(3, 1). From there the graph leaps up to the open dot (3,3)(3, 3) and stays flat at height 33.

Check your understanding

At the boundary x=2x = 2, describe the graph of

k(x)={x2if x≤2,6if x>2.k(x) = \begin{cases} x^2 & \text{if } x \le 2, \\ 6 & \text{if } x > 2. \end{cases}

Answer choices

Domain and range

The domain is the set of inputs covered by the conditions where the selected formulas are defined. The formulas here are defined on their entire listed intervals, so combine those intervals. This combination is their union. For gg, x≤1x\le1 together with x>1x>1 covers all real numbers.

Conditions need not cover every real number. The parking model accepts only h>0h>0; zero and negative stays are outside its intended domain. Within that domain, each input must have exactly one output.

The range is the set of outputs, and you build it one piece at a time. Find the values each piece produces over its own interval, then take the union. A piece is only responsible for the part of its graph that actually gets drawn, so restrict each formula to its interval before reading off its outputs. For gg, the line y=x+1y = x + 1 on x≤1x \le 1 produces every height up to and including 22 (reached at the boundary x=1x = 1). The constant piece contributes only the single height 44. The range of gg is therefore y≤2y \le 2 together with y=4y = 4, with everything strictly between 22 and 44 skipped over by the jump.

Worked example 3 Find the domain and range

Work out the domain and range of

r(x)={1if x<0,x+2if 0≤x≤2,6if x>2.r(x) = \begin{cases} 1 & \text{if } x < 0, \\ x + 2 & \text{if } 0 \le x \le 2, \\ 6 & \text{if } x > 2. \end{cases}

For the domain, list the intervals: x<0x < 0, then 0≤x≤20 \le x \le 2, then x>2x > 2. Together they cover every real number with no overlap, so the domain is all real numbers.

For the range, take the pieces one at a time. The first piece is the constant 11, contributing only the value 11. The middle piece x+2x + 2 runs over the closed interval 0≤x≤20 \le x \le 2, so its outputs run from 0+2=20 + 2 = 2 up to 2+2=42 + 2 = 4, giving every height in 2≤y≤42 \le y \le 4. The third piece is the constant 66, contributing only the value 66. Union the three:

range: y=1,or2≤y≤4,ory=6.\text{range: } y = 1, \quad \text{or} \quad 2 \le y \le 4, \quad \text{or} \quad y = 6.

The range is not a single interval: it has three separate parts. The heights between 11 and 22, and between 44 and 66, are never reached, because the two jumps skip straight over them.

Check your understanding

Find the range of the function

q(x)={x+1if x≤1,4if x>1.q(x) = \begin{cases} x + 1 & \text{if } x \le 1, \\ 4 & \text{if } x > 1. \end{cases}

Answer choices

Absolute value, floor, and ceiling as piecewise functions

Three familiar functions can now be read as piecewise rules. Start with absolute value. Its rule keeps a nonnegative input as is and flips the sign of a negative input, which is precisely a two-piece definition:

∣x∣={xif x≥0,−xif x<0.\lvert x \rvert = \begin{cases} x & \text{if } x \ge 0, \\ -x & \text{if } x < 0. \end{cases}

At the boundary x=0x = 0 the top piece gives 00 and the bottom piece heads toward 00 as well, so the two pieces meet at the same height. That is why the V of the absolute value graph connects at its vertex instead of jumping. There is no gap, just a sharp corner where the slopes switch from −1-1 to +1+1.

Worked example 4 Write an absolute value as a piecewise function

Rewrite ∣x−3∣\lvert x - 3 \rvert without the bars, as a piecewise function.

The bars keep their contents when the inside is zero or positive and negate the contents when the inside is negative, so split on the sign of x−3x - 3. The inside is nonnegative when x−3≥0x - 3 \ge 0, that is x≥3x \ge 3, and negative when x<3x < 3:

∣x−3∣={x−3if x≥3,−(x−3)if x<3.\lvert x - 3 \rvert = \begin{cases} x - 3 & \text{if } x \ge 3, \\ -(x - 3) & \text{if } x < 3. \end{cases}

Tidy the lower piece by distributing the sign, −(x−3)=3−x-(x - 3) = 3 - x, so the function reads x−3x - 3 for x≥3x \ge 3 and 3−x3 - x for x<3x < 3. Check the boundary: at x=3x = 3 the top piece gives 00 and the bottom formula also heads toward 3−3=03 - 3 = 0. The two pieces therefore meet, so the graph is the usual V with its corner at (3,0)(3, 0).

The floor and ceiling are piecewise too, only with infinitely many pieces. The floor holds the constant value nn on each interval n≤x<n+1n \le x < n + 1. So writing one line per integer gives a piecewise definition with a separate constant piece for every integer step. Unlike the absolute value, neighboring floor pieces reach different heights at each integer boundary, one unit apart, so the floor jumps by one at every integer. That is why its graph is a staircase of separate steps rather than a connected curve. A piecewise function with constant pieces like this, whose graph is a row of flat segments, is called a step function. The floor and ceiling are both step functions.

The ceiling has the same step shape, built from its own pieces. It holds the constant value nn on the interval n−1<x≤nn - 1 < x \le n, with the opposite endpoint pattern to a floor step: instead of owning its left endpoint, each ceiling piece owns its right endpoint. That is why the ceiling’s steps land one row higher than the floor’s on most of each interval, and why the two functions agree only exactly at the integers.

Check your understanding

Why is the floor function a piecewise function?

Answer choices

Check your understanding

The floor holds its constant value nn on n≤x<n+1n \le x < n + 1, owning its left endpoint. On which interval does the ceiling hold the constant value nn?

Answer choices

Piecewise models in the real world

Piecewise functions describe rules that change at thresholds, such as the pricing rules below. Postage climbs in jumps as a package crosses weight limits. A parking garage bills one amount for the first hour and another after that. A phone plan charges a flat monthly fee up to some data cap, then a per-gigabyte rate beyond it. A tax model can apply different rates to different bands of income. In every case a single function describes the cost, and its formula depends on which band the input falls into.

Worked example 5 A shipping cost that jumps

A store sets its shipping charge by the order weight ww, in pounds:

C(w)={5if 0<w≤2,8if 2<w≤5,12if w>5.C(w) = \begin{cases} 5 & \text{if } 0 < w \le 2, \\ 8 & \text{if } 2 < w \le 5, \\ 12 & \text{if } w > 5. \end{cases}

Every value is in dollars. Find the charge on orders weighing exactly 22 pounds, 33 pounds, and 5.55.5 pounds, and describe the graph.

An order of exactly 22 pounds sits on a boundary. The first condition 0<w≤20 < w \le 2 includes 22 because of the “or equal to,” so the first tier owns it and the charge is 55 dollars. An order of 33 pounds satisfies 2<w≤52 < w \le 5, so it costs 88 dollars. An order of 5.55.5 pounds satisfies w>5w > 5, so it costs 1212 dollars.

C(2)=5,C(3)=8,C(5.5)=12.C(2) = 5, \qquad C(3) = 8, \qquad C(5.5) = 12.

Because each tier is a constant, the graph is flat within a tier and jumps up at each boundary, exactly a step function like the floor. The boundary weights 22 and 55 each belong to the lower tier, which is why a package right at the limit still ships at the cheaper price. Reading the inequality the other way, so that 22 pounds cost 88 dollars, would overcharge every order that lands exactly on a limit.

Worked example 6 Build a piecewise fare from a description

A taxi charges a flat 33 dollars for any trip up to and including one mile, then 22 dollars for each mile beyond the first. Write the fare F(d)F(d) as a function of the distance dd in miles (with d>0d > 0), and find F(1)F(1) and F(4)F(4).

Up to one mile the fare is the flat charge, 33 dollars, so the first piece is the constant 33 on 0<d≤10 < d \le 1. Past one mile, you still pay the 33 dollars plus 22 dollars for each of the d−1d - 1 extra miles, so the second piece is 3+2(d−1)3 + 2(d - 1) on d>1d > 1:

F(d)={3if 0<d≤1,3+2(d−1)if d>1.F(d) = \begin{cases} 3 & \text{if } 0 < d \le 1, \\ 3 + 2(d - 1) & \text{if } d > 1. \end{cases}

Evaluate. A one-mile trip is on the boundary, which the first piece includes, so F(1)=3F(1) = 3 dollars. A four-mile trip uses the second piece, F(4)=3+2(4−1)=3+6=9F(4) = 3 + 2(4 - 1) = 3 + 6 = 9 dollars.

F(1)=3,F(4)=9.F(1) = 3, \qquad F(4) = 9.

Check the boundary for a jump. At d=1d = 1 the first piece gives 33, and the second formula heads toward 3+2(1−1)=33 + 2(1 - 1) = 3 as well, the same height, so this fare connects with no sudden leap at one mile. The graph still turns a corner there, since the rate changes from flat to rising, but a corner is not a jump. That matches the design, since the extra-mile rate only starts adding once you pass the first mile.

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Core practice

Practice problems at the level of the course, to be worked out on paper. Hints one at a time, then the answer or the full worked solution, with your progress kept in this browser.

Core practice Work it out on paper 10 problems Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

Go deeper (optional)

You can skip this and keep going. Read it if you want to know more.

Why each input must have exactly one output

Why each input must have exactly one output#

Consider two rules, x+1x+1 for x≤1x\le1 and 44 for x≥1x\ge1. At x=1x=1, both conditions hold but the outputs are 22 and 44. That is not a function: one input has two different outputs. If the rules were x+1x+1 for x≤1x\le1 and 22 for x≥1x\ge1, they would agree at the overlap and define a function.

In general, suppose input aa satisfies two conditions with outputs p(a)p(a) and q(a)q(a). If p(a)≠q(a)p(a)\ne q(a), the definition gives two outputs, contradicting the definition of a function. Overlaps are therefore allowed only when the outputs agree. Our convention of one piece per input avoids that problem entirely.

There is a second requirement: every intended input needs an output. Conditions x<1x<1 and x>1x>1 leave 11 out. That is fine if 11 is deliberately outside the domain, but it fails to define a function on all real numbers. In general, an input satisfying no condition has no assigned output.

To avoid both problems, the examples here partition their intended domains: each input belongs to one piece. At a boundary bb that is meant to be included, x≤bx\le b and x>bx>b assign it to the first piece. The alternative x<bx<b and x≥bx\ge b assigns it to the second. Either choice works, provided it matches the intended rule and each selected formula is defined on its assigned inputs.

A bit of history (optional)

Pull a guitar string aside with one finger. Just before release, its idealized shape is two straight segments meeting at your finger: one rule on the left and another on the right. The pieces meet, but the corner is sharp.

Jean d’Alembert’s work on vibrating strings, dated 1747, helped turn that simple picture into a debate about functions. He developed an equation for the moving string, but the mathematical methods he used required smoothness. Could those methods also describe a plucked string with a corner?

The disagreement was concrete: d’Alembert treated the starting shape as one analytical expression, while Leonhard Euler allowed a continuous curve whose different parts could use different expressions. That broader view could include the bent shape of a plucked string. Lagrange joined the discussion, and Daniel Bernoulli approached it mainly through the physics of vibrating strings. (Archibald’s account of the disagreement; history of the vibrating-string problem)

Today’s piecewise notation describes the bent string directly. Its two formulas meet at the same height, so the graph connects even though it has a corner.

Your progress

See all your progress →