Math Core

Lesson 1.5 · Functions

Piecewise functions

Real rules often change partway through. Tax brackets, shipping rates, a phone plan that charges extra after a data cap: each follows one formula up to some point and a different formula after it. A piecewise function captures that in a single function. In precalculus you'll also use piecewise definitions to rewrite absolute values, to build step functions, and to ask a question that leads straight into calculus: do the pieces connect?

Reading a piecewise definition

Definition

Piecewise function

A piecewise function uses different formulas on different parts of its domain. Each formula comes with a condition that says which inputs it applies to, and the conditions don't overlap.

For example,

f(x)={x2−1,x<13−x,1≤x≤42,x>4f(x) = \begin{cases} x^2 - 1, & x < 1 \\ 3 - x, & 1 \le x \le 4 \\ 2, & x > 4 \end{cases}

To evaluate ff at an input, first decide which condition the input satisfies, then use only that formula.

Worked example: Evaluating and graphing

Find f(−2)f(-2), f(1)f(1), f(4)f(4) and f(7)f(7) for the function above, then graph it.

  • −2<1-2 < 1, so use the first piece: f(−2)=4−1=3f(-2) = 4 - 1 = 3.
  • 11 satisfies 1≤x≤41 \le x \le 4, so use the second piece: f(1)=3−1=2f(1) = 3 - 1 = 2.
  • 44 also satisfies 1≤x≤41 \le x \le 4: f(4)=3−4=−1f(4) = 3 - 4 = -1.
  • 7>47 > 4, so f(7)=2f(7) = 2.

To graph, draw each formula only over its own interval. At each boundary, put a closed dot where the endpoint is included and an open dot where it isn't.

The three pieces of f. Open circles at (1, 0) and (4, 2); closed dots at (1, 2) and (4, −1).Open in grapher →

The first piece heads toward (1,0)(1, 0) but doesn't include it, because x<1x < 1. The value at x=1x = 1 belongs to the second piece, so the graph jumps up to the closed dot at (1,2)(1, 2).

Common mistake

Pay attention to ≤\le versus << at each boundary. A boundary input belongs to exactly one piece, and using the wrong piece there is the most common error with piecewise functions. Always check which condition includes the equal sign.

Do the pieces connect?

In the graph above, the pieces don't meet at x=1x = 1 or at x=4x = 4: the graph has jumps there. When the pieces do meet, you can draw the graph without lifting your pencil at that boundary. Calculus calls that property continuity, and you'll study it carefully at the end of this course. For now, here is the practical test.

Joining pieces at a boundary

At a boundary x=cx = c, the graph of a piecewise function has no break when the formula on the left and the formula on the right give the same value at x=cx = c. To make the pieces connect, set the two formulas equal at x=cx = c and solve.

Worked example: Choosing a constant so the pieces connect

Find the value of kk that makes the graph of

f(x)={kx+1,x≤2x2−k,x>2f(x) = \begin{cases} kx + 1, & x \le 2 \\ x^2 - k, & x > 2 \end{cases}

have no break.

At x=2x = 2 the left piece gives 2k+12k + 1 and the right piece gives 4−k4 - k. Set them equal:

2k+1=4−k⟹3k=3⟹k=12k + 1 = 4 - k \quad \Longrightarrow \quad 3k = 3 \quad \Longrightarrow \quad k = 1

With k=1k = 1 both pieces reach the value 33 at x=2x = 2.

With k = 1, the line x + 1 and the parabola x² − 1 meet at (2, 3).Open in grapher →

Absolute value as a piecewise function

The absolute value is secretly piecewise:

∣u∣={u,u≥0−u,u<0\lvert u \rvert = \begin{cases} u, & u \ge 0 \\ -u, & u < 0 \end{cases}

To rewrite an expression like ∣2x−6∣\lvert 2x - 6 \rvert, find where the inside is zero (x=3x = 3) and split there. This turns absolute value problems into ordinary algebra on each piece.

Worked example: Solving an equation with an absolute value

Write g(x)=∣2x−6∣+xg(x) = \lvert 2x - 6 \rvert + x as a piecewise function, then solve g(x)=9g(x) = 9.

For x≥3x \ge 3, 2x−6≥02x - 6 \ge 0, so g(x)=2x−6+x=3x−6g(x) = 2x - 6 + x = 3x - 6.

For x<3x < 3, 2x−6<02x - 6 < 0, so g(x)=−(2x−6)+x=6−xg(x) = -(2x - 6) + x = 6 - x.

g(x)={6−x,x<33x−6,x≥3g(x) = \begin{cases} 6 - x, & x < 3 \\ 3x - 6, & x \ge 3 \end{cases}

Solve on each piece and keep only solutions that satisfy that piece's condition.

  • 6−x=96 - x = 9 gives x=−3x = -3. Since −3<3-3 < 3, it counts.
  • 3x−6=93x - 6 = 9 gives x=5x = 5. Since 5≥35 \ge 3, it counts.

The solutions are x=−3x = -3 and x=5x = 5.

y = |2x - 6| + xy = 9(-3, 9)(5, 9)Open in grapher →

Step functions

A step function is piecewise constant: its graph looks like a staircase. The most important one is the greatest integer function (also called the floor function):

⌊x⌋=the greatest integer less than or equal to x\lfloor x \rfloor = \text{the greatest integer less than or equal to } x

So ⌊3.7⌋=3\lfloor 3.7 \rfloor = 3, ⌊5⌋=5\lfloor 5 \rfloor = 5 and ⌊−2.3⌋=−3\lfloor -2.3 \rfloor = -3. For negatives, "less than or equal to" means moving left on the number line, so −2.3-2.3 rounds down to −3-3, not up to −2-2.

y = ⌊x⌋: each step includes its left endpoint (closed dot) but not its right endpoint.Open in grapher →

Step functions model charges that are rounded up to whole units: parking billed by the started hour, postage by the ounce, phone calls by the started minute.

Worked example: A parking garage

A garage charges $4 for the first hour or any part of it, plus $2.50 for each additional hour or part of an hour. How much does parking cost for 3 hours 12 minutes?

33 hours 1212 minutes is 3.23.2 hours, which starts 44 hours of billing: the first hour plus 33 additional hours. The cost is

4+3(2.50)=11.504 + 3(2.50) = 11.50

dollars. Parking for exactly 33 hours would cost 4+2(2.50)=94 + 2(2.50) = 9 dollars, so the price jumps as soon as the fourth hour begins.

Practice

Practice 1

Let

f(x)={2x+3,x<0x2,0≤x<310−x,x≥3f(x) = \begin{cases} 2x + 3, & x < 0 \\ x^2, & 0 \le x < 3 \\ 10 - x, & x \ge 3 \end{cases}

Find f(3)f(3).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

For the same function ff, find f(−4)+f(2)f(-4) + f(2).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Find ⌊−3.4⌋+⌊3.4⌋\lfloor -3.4 \rfloor + \lfloor 3.4 \rfloor.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 4

Find the value of kk so that the graph of this function has no break:

f(x)={kx2−2,x<2x+k,x≥2f(x) = \begin{cases} kx^2 - 2, & x < 2 \\ x + k, & x \ge 2 \end{cases}

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Solve f(x)=4f(x) = 4 for

f(x)={x2,x<12x+1,x≥1f(x) = \begin{cases} x^2, & x < 1 \\ 2x + 1, & x \ge 1 \end{cases}

Enter all solutions, separated by commas.

Separate answers with commas, e.g. 2, -5

Practice 6

Which piecewise function is equal to ∣x−3∣\lvert x - 3 \rvert?

Practice 7

A parking lot charges $5 for the first hour or any part of it, plus $3 for each additional hour or part of an hour. How many dollars does it cost to park for 4.5 hours?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

Which function has the graph shown?

An open circle at (1, 3.5) and a closed dot at (1, 3).Open in grapher →