Writing a piecewise function means creating a single function that uses different rules for different parts of its domain. Think about it: instead of one formula applying to every input value, a piecewise function changes its formula depending on the interval or condition that the input satisfies. This makes it useful for describing real situations where behavior changes, such as taxi fares, tax brackets, shipping rates, or phone plans.
What Is a Piecewise Function?
A piecewise function, also called a piecewise-defined function, is a function made up of two or more smaller rules. Each rule applies only to a specific set of input values.
A piecewise function usually looks like this:
[ f(x)= \begin{cases} \text{rule 1}, & \text{if condition 1} \ \text{rule 2}, & \text{if condition 2} \ \text{rule 3}, & \text{if condition 3} \end{cases} ]
The most important idea is that the input value determines which rule to use. Here's one way to look at it: if a function has one rule for (x < 0) and another rule for (x \geq 0), you must check the value of (x) before deciding which formula applies.
Why Piecewise Functions Matter
Piecewise functions are helpful because many real-life situations do not follow one simple pattern from beginning to end. A store may charge one price for the first 10 items and a discounted price after that. A delivery service may charge a flat fee for short distances and an additional fee for longer trips. A tax system may apply different rates to different income levels.
Instead of forcing one formula to describe the whole situation, a piecewise function allows each part to have its own rule. This makes the model more accurate and easier to understand.
Step-by-Step: How Do You Write a Piecewise Function?
1. Identify the Different Situations or Intervals
Start by asking: Does the rule change at certain input values?
To give you an idea, suppose a parking garage charges:
- $5 for the first 2 hours
- $3 for every additional hour after 2 hours
The rule changes after 2 hours, so you may need one rule for (0 < t \leq 2) and another rule for (t > 2).
In math problems, the intervals may be given directly, such as:
[ x < -1,\quad -1 \leq x < 3,\quad x \geq 3 ]
In word problems, you often need to find the intervals yourself by looking for phrases such as:
- “for the first…”
- “after…”
- “more than…”
- “less than…”
- “up to…”
- “beyond…”
2. Write a Rule for Each Interval
Once the intervals are clear, write a separate formula for each one.
Here's one way to look at it: suppose a function behaves like this:
- Use (2x + 1) when (x < 0)
- Use (x^2) when (x \geq 0)
The piecewise function is written as:
[ f(x)= \begin{cases} 2x+1, & x<0 \ x^2, & x \geq 0 \end{cases} ]
This means:
- If (x = -3), use (2x + 1), so (f(-3) = 2(-3)+1 = -5)
- If (x = 4), use (x^2), so (f(4) = 4^2 = 16)
3. Use Correct Domain Conditions
The conditions must clearly show which input values belong to each rule. This is where many students make mistakes.
Pay close attention to inequality symbols:
- (<) means the endpoint is not included
- (\leq) means the endpoint is included
- (>) means the endpoint is not included
- (\geq) means the endpoint is included
For example:
[ f(x)= \begin{cases} x+2, & x \leq 1 \ 3x-1, & x > 1 \end{cases} ]
Here, (x = 1) belongs to the first rule, not the second. So:
[ f(1)=1+2=3 ]
If the condition were (x < 1) instead, then (x = 1) would use the second rule Simple, but easy to overlook..
4. Make Sure the Domains Do Not Overlap
A function must give one output for each input. This means the conditions should usually not overlap unless both rules give the same value at the overlapping point.
As an example, this is a problem:
[ f(x)= \begin{cases} x+1, & x < 2 \ 2x, & x \leq 2 \end{cases} ]
The value (x = 2) is not included in the first rule, so this example is actually okay. But if it were:
[ f(x)= \begin{cases} x+1, & x \leq 2 \ 2x, & x \leq 2 \end{cases} ]
then both rules apply at (x = 2), and they give different outputs. That would not be a valid function That's the part that actually makes a difference. Less friction, more output..
A clean piecewise function should divide the domain into clear intervals, such as:
[ x < 2,\quad x = 2,\quad x > 2 ]
or:
[ x \leq 2,\quad x > 2 ]
5. Use the Correct Piecewise Notation
The standard way to write a piecewise function is with a large brace on the left. Each row contains a rule and its condition Turns out it matters..
Example:
[ f(x)= \begin{cases} -1, & x < -2 \ x, & -2 \leq x \leq 4 \ 7, & x > 4 \end{cases} ]
This function has three pieces:
- A constant rule, (-1), for values less than (-2)
- A linear rule, (x), from (-2) to (4), including both endpoints
- A constant rule, (7), for values greater than (4)
Example 1: Writing a Piecewise Function from a Description
Suppose a gym charges:
- $20 per month for the first 3 months
- $15 per month after 3 months
Let (m) represent the number of
months and ( C(m) ) the total cost. Also, for ( m \leq 3 ), the cost is ( 20m ). Still, for ( m > 3 ), the cost is ( 20 \times 3 + 15(m - 3) = 60 + 15(m - 3) ). The piecewise function is:
[
C(m) =
\begin{cases}
20m, & m \leq 3 \
60 + 15(m - 3), & m > 3
\end{cases}
]
This ensures no overlap in conditions and a single output for each ( m ).
Example 2: Absolute Value Function
The absolute value function ( |x| ) is defined as:
[
|x| =
\begin{cases}
-x, & x < 0 \
x, & x \geq 0
\end{cases}
]
At ( x = 0 ), both rules yield ( 0 ), making the function valid.
Example 3: Tax Bracket Calculation
A tax system with brackets:
- 10% on income ( \leq $10,000 )
- 20% on income ( > $10,000 )
Let ( I ) be income and ( T(I) ) the tax. The function is:
[ T(I) = \begin{cases} 0.1I, & I \leq 10000 \ 0.2I, & I > 10000 \end{cases} ]
For ( I = 10000 ), the tax is ( 1000 ); for ( I = 15000 ), it’s ( 3000 ).
Example 4: Step Function
A step function ( f(x) ) defined as:
[
f(x) =
\begin{cases}
1, & x < 0 \
0, & x \geq 0
\end{cases}
]
This creates a "step" at ( x = 0 ), with a clear division between negative and non-negative inputs Less friction, more output..
Example 5: Piecewise Quadratic Function
A function with two quadratic rules:
[
f(x) =
\begin{cases}
x^2 - 4, & x \leq 2 \
2x + 1, & x > 2
\end{cases}
]
At ( x = 2 ), ( f(2) = 2^2 - 4 = 0 ). For ( x = 3 ), ( f(3) = 2(3) + 1 = 7 ) Most people skip this — try not to..
Example 6: Trigonometric Piecewise Function
A function combining sine and cosine:
[
f(x) =
\begin{cases}
\sin(x), & x < \pi \
\cos(x), & x \geq \pi
\end{cases}
]
At ( x = \pi ), ( f(\pi) = \cos(\pi) = -1 ) Small thing, real impact..
Example 7: Rational Function with Restrictions
A function with a denominator restriction:
[
f(x) =
\begin{cases}
\frac{1}{x}, & x \neq 0 \
0, & x = 0
\end{cases}
]
This avoids division by zero at ( x = 0 ) Turns out it matters..
Example 8: Piecewise Function with Multiple Conditions
A function with three intervals:
[
f(x) =
\begin{cases}
x^3, & x < -1 \
-x, & -1 \leq x \leq 1 \
2x, & x > 1
\end{cases}
]
At ( x = -1 ), ( f(-1) = -(-1) = 1 ); at ( x = 1 ), ( f(1) = -1 ) Less friction, more output..
Example 9: Exponential Piecewise Function
A function with exponential rules:
[
f(x) =
\begin{cases}
e^x, & x \leq 0 \
e^{-x}, & x > 0
\end{cases}
]
At ( x = 0 ), ( f(0) = e^0 = 1 ).
Example 10: Piecewise Function with Inequalities
A function using strict and non-strict inequalities:
[
f(x) =
\begin{cases}
x^2, & x < 0 \
0, & x = 0 \
x, & x > 0
\end{cases}
]
This ensures ( x = 0 ) is uniquely defined.
Conclusion
Piecewise functions are powerful tools for modeling scenarios with distinct behaviors across different domains. By carefully defining intervals, avoiding overlaps, and using precise notation, they can accurately represent real-world phenomena such as pricing models, tax brackets, or mathematical functions with abrupt changes. Mastery of piecewise functions enhances problem-solving skills in algebra, calculus, and applied mathematics Less friction, more output..