INAIO Guide Stage 1 3Functions and Graphs
3.5 Piecewise and indicator functions
Choose the right rule on each interval and use zero-one indicators to express a condition.
One formula does not always describe a whole situation. A delivery price may change after a weight limit, and a classifier may switch its decision at a score threshold. A piecewise function records the rule for each range of inputs. An indicator function records whether one condition is true.
This is intermediate work built on functions and Module 2.4's inequality boundaries. OpenStax's piecewise-function examples explain how to read the intervals. Penn State's indicator-variable introduction shows why zero-one rules are useful in data work.
A basic idea: test the condition first
Consider
To find , use the first line and get . To find , use the second line and get . The equality sign at the boundary decides which branch owns . On a graph, an open circle marks an excluded endpoint; a filled circle marks an included one.
A quick tour of rules
A piecewise rule must say where each formula applies. If two branches apply to the same input but give different values, it is not a well-defined function there. If no branch applies, the function is undefined at that input. Always test the boundaries explicitly.
The indicator of a condition is
For a threshold , is below and at or above it. A sum of indicators counts how many conditions hold: if three scores are , , and , then .
You can also use an indicator inside a larger formula. For example, adds an extra charge only when exceeds . Read the condition before calculating the product.
Application 1: a shipping rule
A parcel costs units to ship if it weighs at most kg. Above kg, the cost rises by units per kilogram over kg. What do parcels of kg and kg cost?
- Write both branches. for , and for .
- Check the boundary. Since belongs to the first branch, .
- Use the other branch. For , the extra weight is kg, so .
The rule changes at kg, but the price does not jump there: the second formula approaches as approaches from above.
Application 2: counting flagged messages
A filter flags a message when its score is at least . Four messages have scores , , , and . How many are flagged, and what happens at the exact threshold?
- Write the decision. For score , let .
- Evaluate each score. The outputs are . The score is included because the condition uses .
- Add the indicators. messages are flagged.
The same indicator can be used for every message; summing its outputs turns individual yes-or-no decisions into a count.
Resources
| Source | Title | Why read it |
|---|---|---|
| OpenStax | Domain, range, and piecewise functions | Learn how to evaluate and graph different rules on different intervals. |
| Penn State | The basics of indicator variables | See how a yes-or-no condition can be encoded as 1 or 0. |
Finished this module? Mark it done.
Comments
Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.
Loading comments