Piecewise Function Examples in Math

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Piecewise Function.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in Math.

Concept Recap

A piecewise function is defined by different formulas on different non-overlapping intervals of its domain, with the applicable formula determined by the input value.

A piecewise function is like a rulebook: look up which rule applies to your input value, then use only that rule to compute the output.

Read the full concept explanation โ†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: A piecewise function uses different formulas on different input intervals; the input decides which one applies.

Common stuck point: The procedure for piecewise function is the easy part; the trap is evaluating with the wrong piece. Asking "Does the formula used depend on which interval the input falls into?" first is what keeps a correct-looking calculation from being attached to the wrong concept.

Sense of Study hint: Ask: Does the formula used depend on which interval the input falls into?

Worked Examples

Example 1

easy
Evaluate f(x)={x2x<02x+1xโ‰ฅ0f(x) = \begin{cases} x^2 & x < 0 \\ 2x + 1 & x \geq 0 \end{cases} at x=โˆ’3x = -3, x=0x = 0, and x=4x = 4.

Answer

f(โˆ’3)=9,โ€…โ€Šf(0)=1,โ€…โ€Šf(4)=9f(-3)=9,\; f(0)=1,\; f(4)=9

First step

1
For x=โˆ’3x = -3: since โˆ’3<0-3 < 0, use f(x)=x2f(x) = x^2. So f(โˆ’3)=(โˆ’3)2=9f(-3) = (-3)^2 = 9.

Full solution

  1. 2
    For x=0x = 0: since 0โ‰ฅ00 \geq 0, use f(x)=2x+1f(x) = 2x+1. So f(0)=2(0)+1=1f(0) = 2(0)+1 = 1.
  2. 3
    For x=4x = 4: since 4โ‰ฅ04 \geq 0, use f(x)=2x+1f(x) = 2x+1. So f(4)=2(4)+1=9f(4) = 2(4)+1 = 9.
In a piecewise function, the domain is partitioned into intervals, each with its own rule. The key skill is identifying which interval the input belongs to before applying the corresponding formula.

Example 2

medium
Determine whether f(x)={x+1x<23x=22xโˆ’1x>2f(x) = \begin{cases} x + 1 & x < 2 \\ 3 & x = 2 \\ 2x - 1 & x > 2 \end{cases} is continuous at x=2x = 2.

Example 3

medium
Find the value of aa that makes f(x)={ax+1xโ‰ค2x2โˆ’1x>2f(x) = \begin{cases} ax + 1 & x \le 2 \\ x^2 - 1 & x > 2 \end{cases} continuous at x=2x = 2.

Example 4

medium
Determine whether f(x)={x2+1x<12xxโ‰ฅ1f(x) = \begin{cases} x^2 + 1 & x < 1 \\ 2x & x \ge 1 \end{cases} is continuous at x=1x = 1.

Example 5

medium
For what value of kk is f(x)={kx+1xโ‰ค13xโˆ’1x>1f(x) = \begin{cases} kx + 1 & x \le 1 \\ 3x - 1 & x > 1 \end{cases} continuous at x=1x = 1?

Example 6

medium
A shipping company charges $5 for packages up to 22 lb, $8 for packages over 22 lb but at most 1010 lb, and $12 for packages over 1010 lb. Write the cost C(w)C(w) as a piecewise function.

Example 7

hard
Find aa and bb so that f(x)={ax+bx<1x21โ‰คxโ‰ค2bx+2x>2f(x) = \begin{cases} ax + b & x < 1 \\ x^2 & 1 \le x \le 2 \\ bx + 2 & x > 2 \end{cases} is continuous everywhere.

Example 8

hard
The greatest integer (floor) function is โŒŠxโŒ‹\lfloor x \rfloor. Express โŒŠxโŒ‹\lfloor x \rfloor on [0,3)[0, 3) as a piecewise function.

Example 9

hard
Find all values of cc such that f(x)={cx2+1xโ‰ค12cx+3x>1f(x) = \begin{cases} cx^2 + 1 & x \le 1 \\ 2cx + 3 & x > 1 \end{cases} is continuous at x=1x = 1.

Example 10

challenge
Find aa and bb so that f(x)={x2+axโ‰ค1bx+21<x<35xโ‰ฅ3f(x) = \begin{cases} x^2 + a & x \le 1 \\ bx + 2 & 1 < x < 3 \\ 5 & x \ge 3 \end{cases} is continuous everywhere.

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

easy
Given g(x)={โˆ’xx<โˆ’1x2โˆ’1โ‰คxโ‰ค25x>2g(x) = \begin{cases} -x & x < -1 \\ x^2 & -1 \leq x \leq 2 \\ 5 & x > 2 \end{cases}, evaluate g(โˆ’2)g(-2), g(1)g(1), and g(3)g(3).

Example 2

hard
Find the value of cc so that f(x)={cx+1xโ‰ค3x2โˆ’2x>3f(x) = \begin{cases} cx + 1 & x \leq 3 \\ x^2 - 2 & x > 3 \end{cases} is continuous at x=3x = 3.

Example 3

easy
For f(x)={xx<0x+1xโ‰ฅ0f(x)=\begin{cases}x & x<0\\ x+1 & x\ge 0\end{cases}, find f(โˆ’2)f(-2).

Example 4

easy
For the same ff, find f(3)f(3).

Example 5

easy
For f(x)={5xโ‰ค12xx>1f(x)=\begin{cases}5 & x\le 1\\ 2x & x>1\end{cases}, find f(1)f(1).

Example 6

easy
For the same ff, find f(4)f(4).

Example 7

easy
In the absolute value โˆฃxโˆฃ={xxโ‰ฅ0โˆ’xx<0|x|=\begin{cases}x & x\ge 0\\ -x & x<0\end{cases}, find โˆฃโˆ’5โˆฃ|-5|.

Example 8

easy
How many pieces does f(x)={1x<020โ‰คx<33xโ‰ฅ3f(x)=\begin{cases}1 & x<0\\ 2 & 0\le x<3\\ 3 & x\ge 3\end{cases} have?

Example 9

easy
Should the intervals of a piecewise function overlap?

Example 10

easy
For f(x)={x2xโ‰ค210x>2f(x)=\begin{cases}x^2 & x\le 2\\ 10 & x>2\end{cases}, find f(2)f(2).

Example 11

medium
For f(x)={x+1x<2x2xโ‰ฅ2f(x)=\begin{cases}x+1 & x<2\\ x^2 & x\ge 2\end{cases}, is ff continuous at x=2x=2?

Example 12

medium
For f(x)={2xx<1x+1xโ‰ฅ1f(x)=\begin{cases}2x & x<1\\ x+1 & x\ge 1\end{cases}, is ff continuous at x=1x=1?

Example 13

medium
Evaluate f(โˆ’1)+f(2)f(-1)+f(2) for f(x)={3xx<0x2xโ‰ฅ0f(x)=\begin{cases}3x & x<0\\ x^2 & x\ge 0\end{cases}.

Example 14

medium
A taxi charges $3 for the first mile and $2 per mile after. Write the cost for m>1m>1 miles.

Example 15

medium
For f(x)={โˆ’xx<0x20โ‰คxโ‰ค24x>2f(x)=\begin{cases}-x & x<0\\ x^2 & 0\le x\le 2\\ 4 & x>2\end{cases}, find f(0)f(0) and f(2)f(2).

Example 16

medium
The step function f(x)=โŒŠxโŒ‹f(x)=\lfloor x\rfloor (greatest integer). Find f(2.7)f(2.7) and f(โˆ’1.2)f(-1.2).

Example 17

medium
Find the domain of f(x)={x0โ‰คxโ‰ค48โˆ’xx>4f(x)=\begin{cases}\sqrt{x} & 0\le x\le 4\\ 8-x & x>4\end{cases}.

Example 18

medium
Does f(x)={1xโ‰ค0x+1x>0f(x)=\begin{cases}1 & x\le 0\\ x+1 & x>0\end{cases} have a jump at x=0x=0?

Example 19

medium
For f(x)={x2x<05x=02xx>0f(x)=\begin{cases}x^2 & x<0\\ 5 & x=0\\ 2x & x>0\end{cases}, find f(0)f(0).

Example 20

challenge
Find aa so that f(x)={ax+1x<2x2xโ‰ฅ2f(x)=\begin{cases}ax+1 & x<2\\ x^2 & x\ge 2\end{cases} is continuous at x=2x=2.

Example 21

challenge
Express f(x)=โˆฃxโˆ’3โˆฃf(x)=|x-3| as a piecewise function and find f(1)f(1).

Example 22

challenge
For f(x)={x2x<12xโˆ’1xโ‰ฅ1f(x)=\begin{cases}x^2 & x<1\\ 2x-1 & x\ge 1\end{cases}, find all xx with f(x)=1f(x)=1.

Example 23

easy
For f(x)={2xx<1x+3xโ‰ฅ1f(x) = \begin{cases} 2x & x < 1 \\ x + 3 & x \geq 1 \end{cases}, find f(0)f(0).

Example 24

easy
For the same ff above, find f(5)f(5).

Example 25

easy
A function is f(x)=1f(x) = 1 on x<0x < 0, f(x)=2f(x) = 2 on 0โ‰คx<50 \le x < 5, and f(x)=3f(x) = 3 on xโ‰ฅ5x \ge 5. Find f(5)f(5).

Example 26

easy
For f(x)={x+2xโ‰ค03xx>0f(x) = \begin{cases} x + 2 & x \le 0 \\ 3x & x > 0 \end{cases}, find f(0)f(0).

Example 27

medium
A taxi charges $3 base plus $0.50 per mile for the first 55 miles and $0.30 per additional mile. Write the fare as a piecewise function of miles mm.

Example 28

medium
For f(x)={x+3x<0x20โ‰คxโ‰ค39x>3f(x) = \begin{cases} x + 3 & x < 0 \\ x^2 & 0 \le x \le 3 \\ 9 & x > 3 \end{cases}, find f(โˆ’1)+f(2)+f(4)f(-1) + f(2) + f(4).

Example 29

medium
Solve f(x)=4f(x) = 4 for f(x)={2x+6x<0x2xโ‰ฅ0f(x) = \begin{cases} 2x + 6 & x < 0 \\ x^2 & x \ge 0 \end{cases}.

Example 30

medium
Sketch (describe) the graph of f(x)={โˆ’1x<00x=01x>0f(x) = \begin{cases} -1 & x < 0 \\ 0 & x = 0 \\ 1 & x > 0 \end{cases}.

Example 31

medium
For f(x)={3โˆ’xx<12x=1x2+1x>1f(x) = \begin{cases} 3 - x & x < 1 \\ 2 & x = 1 \\ x^2 + 1 & x > 1 \end{cases}, find the limits limโกxโ†’1โˆ’\lim_{x \to 1^-} and limโกxโ†’1+\lim_{x \to 1^+}.

Example 32

hard
Solve f(x)=5f(x) = 5 for f(x)={x+2x<3x2โˆ’4xโ‰ฅ3f(x) = \begin{cases} x + 2 & x < 3 \\ x^2 - 4 & x \ge 3 \end{cases}.

Example 33

hard
For f(x)={2x+1x<0x2โˆ’3xโ‰ฅ0f(x) = \begin{cases} 2x + 1 & x < 0 \\ x^2 - 3 & x \ge 0 \end{cases}, find the range on [โˆ’2,2][-2, 2].

Background Knowledge

These ideas may be useful before you work through the harder examples.

function definitiondomain