Piecewise Function Examples You Need to Know

What Is a Piecewise Function?

A piecewise function is a function defined by different formulas over different intervals of its domain. Instead of one single rule, you get multiple rules stitched together.

Think of it like a company's pricing model: one rate for the first 10 units, a different rate after that. That's a piecewise function in real life.

The notation looks like this:

f(x) = { formula1 if condition1, formula2 if condition2 }

The curly braces tell you there are multiple cases. Each case has its own condition and its own output rule.

Simple Piecewise Function Examples

Example 1: The Basic Switch

This is the simplest piecewise function you'll encounter:

f(x) = { x if x < 0, x² if x ≥ 0 }

For negative inputs, you get the input back. For zero and positive inputs, you get the square.

So f(-3) = -3, but f(3) = 9.

Easy enough. The function switches its behavior at x = 0.

Example 2: Absolute Value

Here's a function you already use without realizing it's piecewise:

f(x) = { -x if x < 0, x if x ≥ 0 }

This is literally the definition of absolute value. The function flips negative numbers to positive, leaves positive numbers alone.

f(-5) = 5. f(7) = 7.

Most math textbooks introduce absolute value this way. Now you know why the definition looks so weird.

Example 3: The Step Function

Sometimes you need a function that jumps:

f(x) = { 0 if x < 2, 1 if 2 ≤ x < 5, 2 if x ≥ 5 }

This function holds steady, then jumps, holds steady again, then jumps.

It's called a step function because the graph looks like stairs.

Real-world use: postal rates, tax brackets, overtime pay calculations.

Graphing Piecewise Functions

Graphing these requires you to plot each piece in its own interval. Don't try to connect them unless the conditions say so.

Here's how to do it:

The tricky part is those endpoint circles. Get them wrong and you've lost marks for no good reason.

Example: Graphing the Absolute Value Function

For f(x) = |x|, you have:

f(x) = { -x if x < 0, x if x ≥ 0 }

The result is a V shape with the vertex at the origin.

Real-World Piecewise Function Examples

Tax Brackets

Income tax systems use piecewise functions. Here's a simplified version:

Tax(x) = { 0.10x if 0 ≤ x ≤ 10000, 1000 + 0.22(x-10000) if x > 10000 }

You pay 10% on the first $10,000. Everything above that is taxed at 22%.

No politician will admit their tax code is a piecewise function, but that's exactly what it is.

Cell Phone Plans

Most phone plans are piecewise:

Cost(x) = { $30 if 0 ≤ x ≤ 5GB, $30 + $10(x-5) if x > 5GB }

Flat rate up to 5GB, then you pay per gigabyte after that.

Shipping Costs

Online stores love piecewise functions for shipping:

Shipping(w) = { $5 if w ≤ 1lb, $5 + $1.50(w-1) if w > 1lb }

Flat rate up to one pound, then it scales with weight.

Comparing Piecewise Function Types

Type Characteristics Example
Continuous Pieces meet at boundaries, no jumps |x| = { -x, x }
Discontinuous Pieces don't meet, visible jumps Step function
Linear pieces Each piece is a straight line Tax brackets
Nonlinear pieces Contains curves like x² or other functions f(x) = { x if x<0, x² if x≥0 }

Common Mistakes to Avoid

How to Evaluate a Piecewise Function

Evaluating is straightforward once you know the steps:

Step 1: Identify the Input Value

You're given a specific x value. Plug it in.

Step 2: Find the Right Piece

Check which condition your x value satisfies. That's the formula you use.

Step 3: Compute the Output

Apply the formula from step 2.

Example: Evaluate f(3) for f(x) = { x+1 if x<2, 2x-1 if x≥2 }

Since 3 ≥ 2, we use the second piece: f(3) = 2(3) - 1 = 6 - 1 = 5.

Done.

Writing Your Own Piecewise Functions

When you need to create a piecewise function from scratch:

Example task: Write a function that doubles positive numbers and halves negative numbers.

Solution: f(x) = { x/2 if x < 0, 2x if x ≥ 0 }

Test: f(-4) = -2. f(5) = 10. Works.

When Piecewise Functions Show Up

You'll see these in:

They're not just academic exercises. Piecewise functions model real systems that change behavior at specific thresholds.