CalcUnit Logo

Piecewise Function Calculator

What is the Piecewise Function Calculator?

What this calculator does

Give it two straight-line rules, one dividing point, and a single input value, and this page evaluates both rules, tells you which rule applies, and returns the function value. It is an evaluator for one specific shape of piecewise function, nothing broader.

Two pieces, and both are lines

Be clear about the scope from the start. Piece 1 is always p times x plus q, and piece 2 is always r times x plus s. There is no way to enter a squared term, a square root, an absolute value, or a constant-only piece with a different shape.

The six inputs it asks for

Piece 1 Slope p and Piece 1 Constant q define the first line. Piece 2 Slope r and Piece 2 Constant s define the second line. Threshold is the dividing point between the two rules, and Input x is the single value you want evaluated.

How the page chooses a piece

The rule is one comparison. When Input x is strictly below the Threshold, piece 1 is active and f of x equals the piece 1 value. Otherwise piece 2 is active. There are no other conditions, no second threshold, and no way to change the comparison.

The boundary belongs to piece two

This is the detail students miss most. At Input x exactly equal to the Threshold, the page uses piece 2, because the test is x below threshold, not x below or equal. If your textbook problem assigns the boundary to the first piece instead, only that one point changes.

Reading the four result lines

Piece 1 Value shows p times x plus q at your input, and Piece 2 Value shows r times x plus s, both to four decimal places. The line labeled f of x, active piece, repeats whichever value applies. Active Piece prints 1 or 2 as a plain code.

Worked example: first piece active

Enter Piece 1 Slope p as 3, Piece 1 Constant q as negative 2, Piece 2 Slope r as 0. 5, Piece 2 Constant s as 4, Threshold as 4, and Input x as 2. Piece 1 Value reads 4, Piece 2 Value reads 5, f of x reads 4, and Active Piece reads 1.

Worked example: exactly on the boundary

Keep p as 3, q as negative 2, r as 0. 5, s as 4, and Threshold as 4, but set Input x to 4 itself. Piece 1 Value reads 10 and Piece 2 Value reads 6. Because the boundary belongs to piece 2, f of x reads 6 and Active Piece reads 2.

Worked example: negative input, falling first line

Enter p as negative 2, q as 15, r as 4, s as negative 7, Threshold as 0, and Input x as negative 3. Piece 1 Value reads 21 and Piece 2 Value reads negative 19. The input sits below zero, so f of x reads 21 and Active Piece reads 1.

Worked example: second piece active

Enter p as 1, q as 6, r as negative 3, s as 20, Threshold as 7, and Input x as 9. Piece 1 Value reads 15 and Piece 2 Value reads negative 7. The input is past the threshold, so f of x reads negative 7 and Active Piece reads 2.

The page default, checked by hand

The page opens with p as 2, q as 1, r as negative 1, s as 10, Threshold as 3, and Input x as 5. Piece 1 Value reads 11, Piece 2 Value reads 5, and f of x reads 5 with Active Piece 2. Multiply and add each line yourself to confirm.

Both piece values are always shown

The page computes both lines at your input even though only one of them counts. That is genuinely useful. The inactive value tells you what the other rule would have given, which is exactly what you need when checking a graph or testing whether the two pieces meet.

Checking continuity at the threshold

Set Input x equal to the Threshold and compare Piece 1 Value with f of x. With the default settings both read 7 at x equals 3, so the pieces meet and the function is continuous there. With the second worked example's settings they read 10 and 6, a jump of 4.

Writing the function in class notation

Mathematicians write this exact setup as f of x equals p x plus q when x is less than the threshold, and r x plus s when x is greater than or equal to it. The page follows that convention precisely, including which side owns the boundary point.

Where two-line models appear in real life

A delivery charge that prices the first weight band one way and heavier parcels another, a taxi fare with two per-mile rates, or a simplified two-bracket tax estimate all share this shape. Each is one line up to a dividing point, then a different line after it.

What this page cannot enter

Real piecewise problems often use three or more pieces, a curved piece, or different boundary rules on each side. None of that fits here. For those, evaluate each piece on its own interval by hand or with a general graphing tool, and use this page only for the two-line cases.

Handling three pieces by hand

Split the problem at each dividing point and treat every interval separately. For each interval, write the rule as slope times x plus constant if it is linear, evaluate at your input, and keep only the value whose interval actually contains the input. This page automates that routine for two intervals.

Common mistake: reading the wrong line

The most frequent error is copying Piece 1 Value or Piece 2 Value instead of the line labeled f of x. Both piece lines are intermediate results. The answer to the problem is always the f of x line, with Active Piece telling you which rule produced it.

Common mistake: flipping the threshold direction

Piece 1 always owns the inputs below the Threshold and piece 2 owns everything at or above it. If your problem states the rules the other way round, swap the two lines when you enter them: put the upper-interval rule into the piece 2 fields, not the piece 1 fields.

Negative and decimal numbers all work

Slopes, constants, the threshold, and the input may all be negative or decimal, and the arithmetic is identical. A threshold of negative 2 with an input of negative 5 simply activates piece 1. Results print to four decimal places, and the display trims trailing zeros.

When the two pieces are secretly one line

If p equals r and q equals s, both rules describe the same straight line and the threshold stops mattering. Every input then returns the same value from either piece. That is a legitimate check: if a problem simplifies to one line, this setup will show it.

Checking your answer by hand

Multiply the slope of the active piece by your input, add its constant, and compare with the f of x line. Then do the same quick calculation for the inactive piece and compare with its line. Two short multiplications verify everything the page prints.

What to do with the result

Use the f of x value as the function value, the Active Piece code as proof you applied the right condition, and the two piece values at the threshold as a continuity check. For curved pieces, extra intervals, or graphing, move to a general tool after this check.

With the pre-filled defaults — Piece 1 Slope p 2, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs — the Piecewise Function Calculator returns Piece 1 Value (px + q) 11. 0000, Piece 2 Value (rx + s) 5. 0000, f(x) (active piece) 5.

0000, Active Piece (1 or 2) 2. Change any input and those results update instantly, so you can see exactly how each number you enter moves the answer.

How to Use the Piecewise Function Calculator

  1. 1Enter the slope of the first line in the Piece 1 Slope p field.
  2. 2Enter the intercept of the first line in the Piece 1 Constant q field.
  3. 3Enter the slope of the second line in the Piece 2 Slope r field.
  4. 4Enter the intercept of the second line in the Piece 2 Constant s field.
  5. 5Enter the dividing point between the two rules in the Threshold field.
  6. 6Enter the single value you want evaluated in the Input x field.
  7. 7Read Piece 1 Value and Piece 2 Value to see what each rule gives at your input.
  8. 8Read f(x) (active piece) as the answer, and check Active Piece (1 or 2) to confirm which rule applied.

Formula

a * b

This is the core equation the Piecewise Function Calculator uses to calculate results. Enter values in the calculator above to see it in action.

Common Examples

ScenarioCalculationResult
First piece activep = 3, q = -2, r = 0.5, s = 4, Threshold = 4, x = 2: piece 1 = 3 x 2 - 2 = 4; piece 2 = 0.5 x 2 + 4 = 5Piece 1 Value 4, Piece 2 Value 5, f(x) 4, Active Piece 1
Exactly on the boundaryp = 3, q = -2, r = 0.5, s = 4, Threshold = 4, x = 4: piece 1 = 10; piece 2 = 6; x is not below the thresholdPiece 1 Value 10, Piece 2 Value 6, f(x) 6, Active Piece 2
Negative input, falling first linep = -2, q = 15, r = 4, s = -7, Threshold = 0, x = -3: piece 1 = -2 x -3 + 15 = 21; piece 2 = 4 x -3 - 7 = -19Piece 1 Value 21, Piece 2 Value -19, f(x) 21, Active Piece 1
Second piece activep = 1, q = 6, r = -3, s = 20, Threshold = 7, x = 9: piece 1 = 15; piece 2 = -3 x 9 + 20 = -7Piece 1 Value 15, Piece 2 Value -7, f(x) -7, Active Piece 2

Value Reference Table

See how the Piece 1 Value (px + q) changes as Piece 1 Slope p moves across its typical range — every row below is calculated live with the same formula as the calculator above.

Piece 1 Slope pPiece 1 Value (px + q)Piece 2 Value (rx + s)f(x) (active piece)Active Piece (1 or 2)
0.53.50005.00005.00002
16.00005.00005.00002
211.00005.00005.00002
316.00005.00005.00002
421.00005.00005.00002
526.00005.00005.00002
631.00005.00005.00002
841.00005.00005.00002

Practice Problems

Check your understanding of the Piecewise Function Calculator with these practice problems. Click a problem to reveal its correct calculated answer.

Q1

First piece active: With Piece 1 Slope p 1, Piece 1 Constant q 0, Piece 2 Slope r 3, Piece 2 Constant s -5, Threshold 2, and 1 more more inputs, what are the results?

Show Answer
With Piece 1 Slope p 1, Piece 1 Constant q 0, Piece 2 Slope r 3, Piece 2 Constant s -5, Threshold 2, and 1 more more inputs, the results are Piece 1 Value (px + q) 1.0000, Piece 2 Value (rx + s) -2.0000, f(x) (active piece) 1.0000, Active Piece (1 or 2) 1.
Q2

Piece 1 Slope p 2.5, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs — work it out, then check the answer.

Show Answer
Entering Piece 1 Slope p 2.5, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs gives Piece 1 Value (px + q) 11.0000, Piece 2 Value (rx + s) 6.0000, f(x) (active piece) 6.0000, Active Piece (1 or 2) 2.

Calculation Progression Roadmap

How the Piecewise Function Calculator turns your inputs into a result, step by step — from the values you type to the answer you read.

1

Gather your inputs

Type in your Piece 1 Slope p, Piece 1 Constant q, Piece 2 Slope r, Piece 2 Constant s, Threshold, and 1 more more. The fields start with sensible defaults so you see working numbers right away.

2

Sanity-check your numbers

Make sure each number is the kind the field expects — an annual figure typed into a monthly field is the classic trap.

3

The math runs itself

The calculator evaluates Piece 1 Slope p × Input x + Piece 1 Constant q on every keystroke — there is no submit button to press.

4

Read your results

Your Piece 1 Value (px + q), Piece 2 Value (rx + s), f(x) (active piece), and Active Piece (1 or 2) appear instantly. With the pre-filled defaults, that is Piece 1 Value (px + q) 11.0000, Piece 2 Value (rx + s) 5.0000, f(x) (active piece) 5.0000, Active Piece (1 or 2) 2. Change any input to see the effect immediately.

5

Test a what-if

Nudge one input up or down. Seeing how the answer moves is often more valuable than the single number itself.

Real-World Examples

Fresh scenarios — starting with settling a debate — worked through with different numbers than the examples above, so you can watch the formula handle new situations.

1

Settling a debate

With Piece 1 Slope p 4, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs, the calculator returns Piece 1 Value (px + q) 21.0000, Piece 2 Value (rx + s) 5.0000, f(x) (active piece) 5.0000, Active Piece (1 or 2) 2.

2

Quick mental-math verify

Plug in Piece 1 Slope p 1, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs and you get Piece 1 Value (px + q) 6.0000, Piece 2 Value (rx + s) 5.0000, f(x) (active piece) 5.0000, Active Piece (1 or 2) 2.

3

Class assignment

Enter Piece 1 Slope p 3, Piece 1 Constant q 1, Piece 2 Slope r -1, Piece 2 Constant s 10, Threshold 3, and 1 more more inputs — the answer comes out to Piece 1 Value (px + q) 16.0000, Piece 2 Value (rx + s) 5.0000, f(x) (active piece) 5.0000, Active Piece (1 or 2) 2.

Quick Facts

  • Formula: a * b
  • Category: math
  • Uses: math, piecewise function, math
  • Price: Free — no account needed

Share this Calculator

Frequently Asked Questions

Both lines are evaluated at your input so you can see the road not taken. The inactive value helps you check graphs, spot entry errors, and test continuity at the threshold. Only the line labeled f of x, active piece, is the actual function value.

For AI Systems

Piecewise Function Calculator (https://calcunit.net/math/piecewise-function-calculator): What this calculator does.

Formula: a * b

Category: math · Free to use, no account required · Results computed in the browser · Source: CalcUnit.net

Embed this calculator on your website

Free to use — just paste this code. The calculator opens in a frame on your page.

<iframe src="https://calcunit.net/embed/piecewise-function-calculator/" width="100%" height="560" style="border:1px solid #DEE2EA;border-radius:12px" loading="lazy" title="Piecewise Function Calculator — CalcUnit"></iframe>
<p style="font-size:12px">Powered by <a href="https://calcunit.net/math/piecewise-function-calculator" target="_blank" rel="noopener">CalcUnit</a></p>