Skip to content
Math & Scientific

Piecewise Function Calculator

Piecewise Function Calculator

Evaluate a piecewise-defined function at any x — the calculator picks the right piece and shows the substitution.

Piece 1applies when x is below the first boundary
+ Add a piece

Formulas can use x, numbers, +, −, *, /, ^ and parentheses. Writing 2x or 3(x+1) works too.

A Piecewise Function Calculator evaluates functions that change their rule depending on where x sits on the number line. Many real situations work this way: a shipping company charges one rate for light packages and another for heavy ones, or a tax table applies different percentages to different income bands. Instead of one formula for all x, a piecewise function lists two or three formulas, each with its own interval. This calculator takes up to three pieces plus their boundary values, figures out which piece your x belongs to, and evaluates it — showing the substitution step so the answer is transparent.

What the Piecewise Function Calculator Does

The calculator handles piecewise functions with one, two, or three pieces. You type each piece as a formula in x — for example 2*x + 3 or x^2 – 1 — and set the boundary values that separate the pieces. For two pieces there is one boundary b: piece 1 covers x < b and piece 2 covers x ≥ b. For three pieces there are two boundaries b₁ and b₂: piece 1 covers x < b₁, piece 2 covers b₁ ≤ x < b₂, and piece 3 covers x ≥ b₂. Given your x, the calculator selects the correct piece, evaluates the formula, and displays which interval matched and the substitution with your x plugged in. The formula reader understands addition, subtraction, multiplication, division, powers with ^, parentheses, and even shorthand like 2x.

How to Use the Piecewise Function Calculator

Start by typing the x value you want to evaluate into the top box. Piece 1 is always visible: type its formula, using x as the variable. If your function has more pieces, press “+ Add a piece” to reveal piece 2, and again for piece 3; “− Remove last piece” hides the last one if you added too many. Each boundary box sits on the piece to its left: the boundary after piece 1 separates pieces 1 and 2, and the boundary after piece 2 separates pieces 2 and 3. Boundaries must be numbers in increasing order. Press Calculate to see f(x) as a headline number, which piece was used, and the substitution line. Press Reset to start over. A boundary value itself always belongs to the piece on its right.

How Piecewise Functions Work

A piecewise function is written as a brace grouping several rules, each tagged with the x-values it governs. The boundaries are the cut points where the rule switches — think of them as fences between neighboring fields. Evaluating f(a) is a two-step job: first locate a on the number line relative to the fences, then apply only the rule for that field. The most common mistake is applying the wrong piece, especially near a boundary, which is exactly the step this calculator makes explicit by naming the winning piece and the inequality it satisfied, such as 0 ≤ 2 < 3. Note the convention used here and in most textbooks: when x lands exactly on a boundary, the piece to the right (the higher-numbered one) wins.

Worked Example: Three Pieces at x = 2

Define f(x) = x^2 for x < 0, 2x + 1 for 0 ≤ x < 3, and 10 − x for x ≥ 3. Add two pieces so all three rows show, enter the formulas x^2, 2*x + 1, and 10 – x, set the boundaries to 0 and 3, enter x = 2, and press Calculate. Step 1 — pick the piece: 2 satisfies 0 ≤ 2 < 3, so piece 2 applies. Step 2 — substitute: f(2) = 2*(2) + 1 = 4 + 1 = 5. The headline answer is 5. Try x = −2 as well: −2 < 0, so piece 1 applies and f(−2) = (−2)^2 = 4. And x = 5: 5 ≥ 3, so piece 3 applies and f(5) = 10 − (5) = 5. One function, three different rules, three correct answers.

Worked Example: Two Pieces at the Boundary

Define g(x) = 3x for x < 2 and x^2 − 1 for x ≥ 2. Add one piece, enter 3*x and x^2 – 1, set the boundary to 2, enter x = 2, and press Calculate. Step 1: x = 2 satisfies 2 ≥ 2, so piece 2 applies — remember, a boundary belongs to the piece on its right. Step 2: the calculator shows f(2) = (2)^2 − 1 = 4 − 1 = 3. The answer is 3. Now try x = −1: −1 < 2, so piece 1 applies and f(−1) = 3*(−1) = −3. This example is worth studying because the boundary case is where hand calculations most often go wrong — students frequently plug x = 2 into the first piece and get 6 instead of the correct 3.

Worked Example: A Single Piece

Not every use needs multiple pieces: h(x) = 5x − 2 for all x. Leave the calculator at one piece, enter 5*x – 2, set x = 4, and press Calculate. With a single piece there are no boundaries to set — the boundary box is hidden automatically. The result is f(4) = 5*(4) − 2 = 20 − 2 = 18. The single-piece mode is handy as a general function evaluator when you want the substitution shown step by step, for instance while checking homework. It also demonstrates the convention clearly: one rule, every x, no decisions needed.

Reading Your Result

The large number is f(x), the value of the function at your x. Above the working, the result names which piece applied and why: the exact inequality your x satisfied, such as −2 < 0 or 2 ≥ 2. The substitution line then shows the piece’s formula with your x inserted in parentheses — f(2) = 2*(2) + 1 — followed by the evaluated answer. If the calculator reports an error instead, read it carefully: it distinguishes between a missing x, a missing or non-numeric boundary, boundaries out of order, an empty formula, and a formula that cannot be evaluated at your x (like division by zero). Each message tells you precisely which box to fix.

Common Mistakes With Piecewise Functions

Using the wrong piece is the classic error, especially at or near a boundary — always test the inequality rather than guessing. Related to that is the boundary convention: x equal to a boundary belongs to the right-hand piece here, so g(2) in the example above is 3, not 6. Another mistake is entering boundaries out of order; the fences must run left to right, b₁ < b₂, or the intervals overlap and nothing is well-defined. Formula typos are common too: the reader needs x as the variable (capital X works as well), ^ for powers, and * for multiplication, though 2x shorthand is accepted. Finally, remember that each piece’s formula only applies inside its own interval — simplifying across a boundary is meaningless.

Frequently Asked Questions

1. What is a piecewise function?

A function defined by different formulas on different parts of its domain. Each formula comes with the interval of x-values where it applies, and the intervals together cover the whole number line.

2. How do I evaluate f(a) for a piecewise function?

First find which interval contains a, then plug a into that interval’s formula only. The calculator automates both steps and shows its choice.

3. What happens exactly at a boundary value?

The piece to the right is used. If the boundary is 2, then x = 2 follows the piece for x ≥ 2, not the piece for x < 2. This matches standard textbook convention.

4. How many pieces can I enter?

Up to three. One piece covers the whole number line, two pieces need one boundary, and three pieces need two boundaries in increasing order.

5. How do I write powers in a formula?

Use the ^ symbol: x^2 means x squared, x^3 means x cubed. Parentheses work as usual, so (x + 1)^2 squares the whole sum.

6. Do I need the * sign for multiplication?

Usually, but the calculator also accepts shorthand: 2x means 2*x, and 3(x + 1) means 3*(x + 1). When in doubt, include the * — it always works.

7. Can I use capital X in formulas?

Yes. Capital X is converted to lowercase x automatically, so 2X + 3 and 2x + 3 give the same result.

8. Why do boundaries have to increase left to right?

Because each boundary is a fence between neighboring intervals. If the second fence were left of the first, the middle interval would be empty or backwards, and the function would be undefined there.

9. What does “division by zero” mean here?

Some formulas blow up at specific x values — for example 1/(x − 2) at x = 2. The calculator detects this and tells you the piece has no real value at your x instead of showing a nonsense answer.

10. Can a piecewise function be continuous?

Yes, if the pieces meet at the boundaries. In the three-piece example, piece 2 at x = 3 gives 7 while piece 3 gives 7 too — actually 2(3) + 1 = 7 and 10 − 3 = 7, so that function is continuous at x = 3. Many piecewise functions jump instead.

11. What are piecewise functions used for?

Tax brackets, shipping rates, tiered pricing, and absolute-value definitions all work this way. Any rule that changes at thresholds is naturally piecewise.

12. How is the absolute value function piecewise?

|x| equals −x when x < 0 and x when x ≥ 0. Enter −x with boundary 0 and x as the second piece to evaluate absolute values with this calculator.

13. Can I graph the function with this tool?

The calculator evaluates at points rather than drawing. Evaluating at several x values across each interval gives you the points needed to sketch the graph by hand.

14. Why did I get the wrong piece in my hand calculation?

Almost always a boundary slip: either the inequality was tested backwards, or the boundary value was assigned to the left piece instead of the right one. Re-check with the inequality written out.

15. What if my function has more than three pieces?

Split it into groups of three and evaluate each group separately, or evaluate the extra pieces by hand. Three pieces cover the overwhelming majority of textbook and practical problems.

Final Thoughts

Piecewise functions look fussy until you see the pattern: locate x, pick the rule, plug in. The Piecewise Function Calculator makes the first two steps visible so the third is just arithmetic. Practice with the boundary cases — that is where understanding is built — and functions that switch rules will stop feeling like a trick and start feeling like a tool.