| Rule f(x) | Condition |
|---|
Conditions can be x < 0, 0 <= x < 2, x >= 2, or one final otherwise rule.
Define rules with conditions, evaluate values, validate gaps and overlaps, and graph each piece in its own color.
Results are calculated automatically as you enter data.
| Rule f(x) | Condition |
|---|
Conditions can be x < 0, 0 <= x < 2, x >= 2, or one final otherwise rule.
▼ See explanations and tips below ▼
A piecewise function is a function that uses different formulas on different parts of its domain. Instead of one rule applying to every possible input, each rule applies only when its condition is true.
A simple piecewise function might look like this:
This means:
The main idea is that the input value decides which formula is active. Once you identify the correct interval or inequality, evaluating the function is usually just ordinary substitution.
Piecewise functions are useful when a relationship changes at specific breakpoints. They appear in algebra, precalculus, calculus, physics, economics, computer science, grading systems, step functions, absolute value functions, and many real-world rules with thresholds.
Piecewise functions help describe situations where one formula is not enough. Many real-world relationships behave differently in different ranges. For example, a rule might change after a deadline, a cost might change after a quantity threshold, or a graph might switch from a line to a curve at a boundary.
They also help students learn important function ideas:
A piecewise function is still one function only when each allowed input has exactly one output. That is why the conditions matter as much as the formulas.
To evaluate a piecewise function, follow the conditions first and the formulas second.
For example, consider:
To find \(f(-3)\), use the first piece because \(-3 < 0\):
To find \(f(1.5)\), use the second piece because \(0 \le 1.5 < 2\):
To find \(f(2)\), use the third piece because \(2 \ge 2\):
Notice that \(x=2\) is not part of the middle interval \(0 \le x < 2\), because the symbol \(<\) excludes \(2\). It is part of the last interval \(x \ge 2\), because the symbol \(\ge\) includes \(2\).
A well-defined piecewise function should avoid both gaps and overlaps. Ideally, each input in the intended domain should match one rule and only one rule.
To graph a piecewise function, graph each formula only on the interval where it applies. Then mark boundary points carefully.
For the function
there are three graph pieces:
At \(x=0\), the first piece is open because \(x<0\) does not include \(0\), while the second piece is closed because \(0 \le x\) includes \(0\). At \(x=2\), the second piece is open and the third piece is closed.
Open and closed endpoints are not just graphing details. They decide whether the function has a value at the boundary and which rule gives that value.
Suppose
Find \(g(2)\) and \(g(3)\).
For \(x=2\), use the first piece because \(2<3\):
For \(x=3\), use the second piece because \(3 \ge 3\):
The boundary value \(3\) belongs to the second piece, not the first one.
Suppose
The input \(x=1\) is not covered by either condition. The first condition excludes \(1\), and the second condition also excludes \(1\).
So \(h(1)\) is undefined:
This is a gap at \(x=1\).
Suppose
At \(x=2\), both conditions are true. The first rule gives:
The second rule gives:
Because two different rules apply at the same input, the function is ambiguous at \(x=2\). A calculator may treat this as undefined or warn that more than one rule matches.
The absolute value function can be written piecewise as:
This works because negative inputs are made positive by multiplying by \(-1\), while zero and positive inputs stay the same.
For example:
and
A piecewise function result tells you which rule applies at a specific input and what output that rule produces.
If the result is defined, it means exactly one condition matched the entered \(x\) value and the corresponding expression produced a finite output.
If no rule matches, the function is undefined at that input. This usually means there is a gap in the conditions.
If more than one rule matches, the function is ambiguous at that input. This usually means the conditions overlap. Even if two overlapping formulas happen to give the same number at one point, overlapping conditions can still make the function setup unclear and should be fixed.
When reviewing graph and status results, pay attention to these ideas:
A graph helps you see the pieces, endpoints, jumps, and gaps, but it is still a numerical drawing. Use the conditions to confirm exact boundary behavior.
Some piecewise function tools also estimate calculus information. These estimates are helpful for exploration, but they should not be confused with exact symbolic calculus.
A numerical derivative estimate often uses nearby points to approximate the local slope. A common central-difference estimate is:
where \(h\) is a small step size. This calculator now refines a scale-aware step and compares left- and right-hand slopes. At a boundary it reports a one-sided estimate, a converged two-sided estimate, or that the derivative does not exist instead of blindly averaging incompatible pieces.
This estimate can work well on a smooth part of a piecewise function, but it can be misleading near:
For example, the absolute value function has a sharp corner at \(x=0\). The graph has a left-hand slope of \(-1\) and a right-hand slope of \(1\), so the ordinary derivative does not exist at that point even though nearby numerical estimates may produce a value.
A numerical integral estimate approximates signed area over an interval. Adaptive Gauss-Kronrod quadrature compares embedded formulas on each subinterval and subdivides where their estimates do not agree closely enough.
Here \(Q_K\) is the Kronrod estimate and \(Q_G\) is the embedded Gauss estimate. Their difference guides further subdivision.
In this calculator, the integral runs from the lower end of the graph range to the entered evaluation value. It is split at exact condition boundaries and evaluated with adaptive Gauss-Kronrod quadrature. The result includes an error estimate and evaluation count; it is withheld when an open interval is uncovered or ambiguous, the integrand is non-finite, or convergence limits are reached.
Using the wrong piece. Always check the condition before substituting the input into a formula. The formula is only valid on its assigned interval.
Ignoring open and closed endpoints. The difference between \(x<2\) and \(x\le 2\) matters. One excludes \(2\); the other includes it.
Leaving a gap unintentionally. Conditions such as \(x<1\) and \(x>1\) leave \(x=1\) uncovered.
Creating an overlap unintentionally. Conditions such as \(x\le 1\) and \(x\ge 1\) both include \(x=1\).
Expecting rule order to fix overlaps. In some programming contexts, the first matching rule may be used. In this calculator, overlapping rules are treated as ambiguous rather than being resolved by order.
Using malformed or unsupported notation. The parser accepts implicit multiplication such as 2x and explicit multiplication such as 2*x. Use the variable \(x\), supported function names, and complete expressions.
Using equality-only point rules. A condition such as \(x=1\) is not supported by this calculator’s condition format. Use supported inequalities and intervals.
Treating numerical estimates as exact. Numerical derivative and integral results are approximations. They are especially sensitive near discontinuities and sharp changes.
Assuming the evaluation value must be inside the graph range. The graph range controls the displayed graph and the starting point for the integral estimate, but the entered \(x\) value is not automatically restricted to that range.
Use piecewise functions when a relationship has different rules for different input ranges.
Common uses include:
Piecewise notation is especially useful when the formula changes at clear boundary values.
Piecewise functions are powerful, but they require careful setup. A small condition error can change the function’s value or make the function undefined.
For this calculator, keep these limitations in mind:
otherwise / else fallback. Decimal and scientific-notation boundaries are supported.
2x and 2*x are accepted.
For homework, exams, engineering work, scientific work, or any decision where accuracy matters, use the calculator as a checking and visualization tool. Verify important boundary points and exact symbolic results separately.
-5, 5.
A function is piecewise when it is defined by different formulas on different parts of its domain. Each formula has a condition that tells when it applies. The input value determines which formula is used.
First, find the condition that contains the given input value. Then substitute the input into that rule’s formula. Do not substitute into every formula unless you are checking for gaps or overlaps.
If no condition matches, the function is undefined at that input. This usually means there is a gap in the intervals or inequalities. Check boundary symbols such as \(<\), \(\le\), \(>\), and \(\ge\) carefully.
If two conditions match the same input, the setup has an overlap. A well-defined function should give only one output for each input. This calculator treats overlapping rules as ambiguous instead of choosing the first rule automatically.
Open and closed endpoints decide whether a boundary value is included in a piece. For example, \(x<2\) excludes \(2\), while \(x\le 2\) includes it. This can change the value of the function and the appearance of the graph.
Yes. A piecewise function can be continuous if its pieces connect correctly at their boundary points and the function is defined there. To check a boundary, compare the left-hand behavior, right-hand behavior, and the actual function value at that point.
No. The derivative and integral cards are numerical estimates. They can be useful for checking local slope or approximate area, but they are not symbolic derivatives, exact antiderivatives, or formal continuity proofs.
Books
Online and University Sources