Piecewise Functions

A piecewise function uses different formulas for different input ranges, letting you define relationships that change behavior at specific boundaries.

f(x)={f1(x)xD1f2(x)xD2f(x) = \begin{cases} f_1(x) & x \in D_1 \\ f_2(x) & x \in D_2 \end{cases}

Solve a problem with Piecewise Functions

Type the problem. The solver will use Piecewise Functions where Piecewise Functions is the right tool, and tell you when it is not.

Drag one in or paste from the clipboard. JPEG, PNG or WebP. You get the transcription to check before anything is solved.

How to get a better answer
  • Paste the whole problem, including the instruction word — "simplify", "solve for x" and "factor" lead to three different answers.
  • Say what you have already tried. "I got x = 4 and the book says 2" turns a solution into a diagnosis.
  • Set the level in the settings button. A calculus shortcut is not a better answer if you have not met derivatives yet.
  • For a photo, get the whole problem in frame and hold the page flat — you get the transcription to fix before anything is solved.

What each symbol means

What Piecewise Functions takes
ff
xx
Piecewise Functions
SymbolMeaning
ffThe piecewise function itself, which consists of multiple sub-functions applied to different input regions; treating it as a single unchanging rule rather than recognizing its multi-part nature will cause you to apply the wrong formula for some inputs.
xxThe input variable (independent variable) whose value determines which piece of the function to use; each value of xx belongs to exactly one of the domain regions D1,D2D_1, D_2, etc.

When to use it

Use a piecewise function when the rule or formula for a relationship changes depending on the value of the input.

Level

Usually taught in: Algebra II

Worked examples

1. Evaluate a piecewise function at multiple points

Problem

Evaluate f(2)f(2) and f(1)f(-1) where f(x)={2x+1x0xx<0f(x) = \begin{cases} 2x + 1 & x \geq 0 \\ -x & x < 0 \end{cases}.
  1. f(2)=2(2)+1f(2) = 2(2) + 1

    Since 202 \geq 0, we use the first piece of the function.

  2. f(2)=4+1f(2) = 4 + 1

    Multiply: 22=42 \cdot 2 = 4.

  3. f(2)=5f(2) = 5

    Add: 4+1=54 + 1 = 5.

  4. f(1)=(1)f(-1) = -(-1)

    Since 1<0-1 < 0, we use the second piece of the function.

  5. f(1)=1f(-1) = 1

    Negate: (1)=1-(-1) = 1.

Answer: f(2)=5 and f(1)=1f(2) = 5 \text{ and } f(-1) = 1

Piecewise functions require you to first identify which interval contains your input, then apply the corresponding formula; the same function ff gives different outputs for different inputs because they use different rules.

2. Evaluate with negative input and check boundary conditions

Problem

Find f(0)f(0) and f(3)f(-3) where f(x)={12x+2x>0x2x0f(x) = \begin{cases} \frac{1}{2}x + 2 & x > 0 \\ -x^2 & x \leq 0 \end{cases}.
  1. f(0)=(0)2f(0) = -(0)^2

    Since 000 \not> 0 but 000 \leq 0, we use the second piece x2-x^2.

  2. f(0)=(0)f(0) = -(0)

    Square: 02=00^2 = 0.

  3. f(0)=0f(0) = 0

    Negate: (0)=0-(0) = 0.

  4. f(3)=(3)2f(-3) = -(-3)^2

    Since 30-3 \leq 0, we use the second piece x2-x^2.

  5. f(3)=(9)f(-3) = -(9)

    Square: (3)2=9(-3)^2 = 9.

  6. f(3)=9f(-3) = -9

    Negate: (9)=9-(9) = -9.

Answer: f(0)=0 and f(3)=9f(0) = 0 \text{ and } f(-3) = -9

Piecewise functions require careful attention to boundary conditions and inequality symbols; here, the boundary value x=0x = 0 belongs to the second piece because of the condition x0x \leq 0 (which includes equality), not the first piece with x>0x > 0.

3. Model temperature changes in a laboratory

Problem

A laboratory measures temperature during an experiment. From t=0t = 0 to t=4t = 4 hours, temperature rises from 20°C at a rate of 3°C per hour. From t=4t = 4 to t=8t = 8 hours, temperature falls at a rate of 2°C per hour. Write the piecewise temperature function T(t)T(t) and find the temperature at t=2t = 2 hours and t=6t = 6 hours.
  1. T(t)={20+3t0t4402t4<t8T(t) = \begin{cases} 20 + 3t & 0 \leq t \leq 4 \\ 40 - 2t & 4 < t \leq 8 \end{cases}

    For the first interval, temperature starts at 20°C and increases 3°C per hour. At t=4t = 4, we have 20+3(4)=3220 + 3(4) = 32°C. For the second interval starting from 32°C and decreasing 2°C per hour, the formula is 322(t4)=402t32 - 2(t - 4) = 40 - 2t.

  2. T(2)=20+3(2)T(2) = 20 + 3(2)

    Since 22 is in the interval 0t40 \leq t \leq 4, we use the first formula.

  3. T(2)=20+6T(2) = 20 + 6

    Multiply: 32=63 \cdot 2 = 6.

  4. T(2)=26T(2) = 26

    Add: 20+6=2620 + 6 = 26.

  5. T(6)=402(6)T(6) = 40 - 2(6)

    Since 66 is in the interval 4<t84 < t \leq 8, we use the second formula.

  6. T(6)=4012T(6) = 40 - 12

    Multiply: 26=122 \cdot 6 = 12.

  7. T(6)=28T(6) = 28

    Subtract: 4012=2840 - 12 = 28.

Answer: T(2)=26°C and T(6)=28°CT(2) = 26 \text{°C and } T(6) = 28 \text{°C}

Real-world situations like temperature change over time often involve different rates of change over different time periods; piecewise functions are the natural way to model these changes by defining separate formulas for each time interval.

Common mistakes

Where Piecewise Functions usually goes wrong
Answer came out wrong
f(2)=2(2)+1=4+1=3f(-2) = 2(-2) + 1 = -4 + 1 = -3 when evaluating f(x)={2x+1x0xx<0f(x) = \begin{cases} 2x + 1 & x \geq 0 \\ x & x < 0 \end{cases}
Before applying any formula, check which interval contains your input: does 20-2 \geq 0? No. Does 2<0-2 < 0? Yes. So use the second piece: f(2)=2f(-2) = -2.
Using the same formula for both x=5x = 5 and x=5.1x = 5.1 when the first piece is defined as x<5x < 5.
Check the exact boundary inequality: << means the boundary is excluded (so 5 does not belong to x<5x < 5), while \leq means it is included (so 5 does belong to x5x \leq 5). Always match your input to the exact inequality.
Assuming the two pieces must connect at the boundary and treating the function as 'wrong' if they do not.
Do not assume continuity unless the problem explicitly requires it; verify by checking whether the output of one piece at the boundary equals the output of the adjacent piece, but understand that a jump is normal and correct in piecewise functions.
The mistakeWhy it is wrongThe fix
f(2)=2(2)+1=4+1=3f(-2) = 2(-2) + 1 = -4 + 1 = -3 when evaluating f(x)={2x+1x0xx<0f(x) = \begin{cases} 2x + 1 & x \geq 0 \\ x & x < 0 \end{cases}This student applied the first piece (valid for x0x \geq 0) to the input x=2x = -2, which actually belongs to the second piece where x<0x < 0.Before applying any formula, check which interval contains your input: does 20-2 \geq 0? No. Does 2<0-2 < 0? Yes. So use the second piece: f(2)=2f(-2) = -2.
Using the same formula for both x=5x = 5 and x=5.1x = 5.1 when the first piece is defined as x<5x < 5.Confusing inequality symbols; the symbol << does not include the boundary value, so x=5x = 5 does not satisfy x<5x < 5.Check the exact boundary inequality: << means the boundary is excluded (so 5 does not belong to x<5x < 5), while \leq means it is included (so 5 does belong to x5x \leq 5). Always match your input to the exact inequality.
Assuming the two pieces must connect at the boundary and treating the function as 'wrong' if they do not.Piecewise functions are designed precisely to model situations where behavior changes abruptly; a jump discontinuity (where pieces do not connect) is intentional and expected in many real-world applications like tax brackets or price changes.Do not assume continuity unless the problem explicitly requires it; verify by checking whether the output of one piece at the boundary equals the output of the adjacent piece, but understand that a jump is normal and correct in piecewise functions.

Tips and when to use something else

  • Always identify which interval your input belongs to before applying any formula; this single step prevents most errors with piecewise functions.
  • Pay close attention to inequality symbols: << and >> exclude the boundary, while \leq and \geq include it. One wrong symbol means you apply the wrong piece.
  • If a function can be written as a single formula without branches, write it that way instead; piecewise notation is for situations where the rule genuinely changes.
  • Jump discontinuities (where pieces do not connect at boundaries) are normal and intentional in piecewise functions; they model real situations like price brackets or tax rates that change abruptly.

Frequently asked questions

How do I know which piece of a piecewise function to use?
Check the value of your input against the inequality condition in each piece. Find the piece whose condition is true, and apply that formula. For example, if x=3x = -3 and one piece has x>0x > 0, that condition is false so do not use that piece; if another has x0x \leq 0, that condition is true so use it.
Why do piecewise functions have different formulas?
Real situations often have different rules in different contexts: a phone plan charges one rate for the first 1000 minutes and another rate beyond that, or temperature might rise at one rate during the day and fall at a different rate at night. Piecewise functions model these natural changes in behavior.
Can a piecewise function be continuous at the boundary?
Yes, it is possible. If the output of one piece at the boundary equals the output of the next piece, then the function is continuous at that point and there is no jump. However, piecewise functions often have jump discontinuities by design, and this is perfectly correct—do not assume continuity unless the problem asks for it.
How do I graph a piecewise function?
Graph each piece separately over its own interval, then combine them. For the first interval, plot the first formula but only for xx values in its domain; for the second interval, plot the second formula but only for its xx values. Use open circles to show excluded endpoints (from << or >>) and closed circles to show included endpoints (from \leq or \geq).

Need a different method?

The full solver is not scoped to one formula — type any problem and it will pick the method.

Open the math solver

Reviewed 2026-09-18