Mathwords logoReference LibraryMathwords

Piecewise Function

Piecewise Function

A function that uses different formulas for different parts of its domain.

 

Example of piecewise function f(x) = 1−x if x≤−2, x² if −2<x≤3, 5 if x>3, with f(−5)=6, f(1)=1, f(12)=5.

Key Formula

f(x)={formula1,if xD1formula2,if xD2formulan,if xDnf(x) = \begin{cases} \text{formula}_1, & \text{if } x \in D_1 \\ \text{formula}_2, & \text{if } x \in D_2 \\ \vdots \\ \text{formula}_n, & \text{if } x \in D_n \end{cases}
Where:
  • xx = The input value
  • D1,D2,,DnD_1, D_2, \ldots, D_n = Non-overlapping intervals that together make up the domain
  • formula1,,formulan\text{formula}_1, \ldots, \text{formula}_n = The different rules applied on each interval

Worked Example

Problem: Given the piecewise function below, evaluate f(−3), f(0), and f(4). f(x) = { 2x + 1 if x < 0; x² if x ≥ 0 }
Step 1: Evaluate f(−3). Since −3 < 0, use the first formula.
f(3)=2(3)+1=6+1=5f(-3) = 2(-3) + 1 = -6 + 1 = -5
Step 2: Evaluate f(0). Since 0 ≥ 0, use the second formula.
f(0)=02=0f(0) = 0^2 = 0
Step 3: Evaluate f(4). Since 4 ≥ 0, use the second formula.
f(4)=42=16f(4) = 4^2 = 16
Answer: f(−3) = −5, f(0) = 0, and f(4) = 16.

Another Example

Problem: A parking garage charges 2perhourforthefirst3hoursand2 per hour for the first 3 hours and5 per hour for every hour after that. Write a piecewise function C(t) for the cost and find the cost for 5 hours.
Step 1: Identify the two pricing rules. For the first 3 hours (0 < t ≤ 3), the rate is 2/hr.Fortimebeyond3hours(t>3),thefirst3hourscost2/hr. For time beyond 3 hours (t > 3), the first 3 hours cost6 total, then each additional hour costs $5.
C(t)={2t,if 0<t36+5(t3),if t>3C(t) = \begin{cases} 2t, & \text{if } 0 < t \leq 3 \\ 6 + 5(t - 3), & \text{if } t > 3 \end{cases}
Step 2: Evaluate C(5). Since 5 > 3, use the second formula.
C(5)=6+5(53)=6+5(2)=6+10=16C(5) = 6 + 5(5 - 3) = 6 + 5(2) = 6 + 10 = 16
Answer: Parking for 5 hours costs $16.

Frequently Asked Questions

How do you graph a piecewise function?
Graph each formula only over its specified interval. Use a solid dot (●) at an endpoint if that endpoint is included (≤ or ≥) and an open dot (○) if it is not included (< or >). Then combine all the pieces on a single set of axes. The result may have jumps, corners, or gaps depending on the formulas.
Can a piecewise function be continuous?
Yes. A piecewise function is continuous if, at every boundary between intervals, the two neighboring formulas produce the same output value. For example, f(x) = { x if x < 1; 2x − 1 if x ≥ 1 } is continuous at x = 1 because both pieces give f(1) = 1. If the values do not match, there is a jump discontinuity.

Piecewise function vs. Absolute value function

The absolute value function |x| is actually a specific piecewise function: it equals x when x ≥ 0 and −x when x < 0. So every absolute value function can be written in piecewise form, but piecewise functions are far more general — they can have any number of pieces with any formulas.

Why It Matters

Piecewise functions model real situations where the rule changes depending on conditions. Tax brackets, shipping rates, and speed limits all follow different formulas in different ranges. In calculus, studying where the pieces meet teaches you about continuity and differentiability at a point.

Common Mistakes

Mistake: Using the wrong formula because you misread the inequality direction or confuse strict (<) with non-strict (≤) inequalities.
Correction: Before substituting, carefully check which interval your input belongs to. Pay special attention to boundary points — a value like x = 0 belongs to whichever piece includes the equals sign.
Mistake: Allowing the intervals to overlap so that one input produces two different outputs.
Correction: A function can only assign one output per input. Make sure the domain intervals do not overlap. At each boundary, exactly one piece should claim the endpoint.

Related Terms

  • FunctionGeneral concept that piecewise functions extend
  • DomainSplit into intervals for each piece
  • FormulaEach piece uses a different formula
  • Absolute Value FunctionA common two-piece piecewise function
  • ContinuousPiecewise functions may or may not be continuous
  • Step FunctionPiecewise function with constant pieces
  • IntervalDefines each sub-domain for a piece