Skip to content
ihateDesmos

Piecewise function grapher

A piecewise function uses different formulas on different parts of its domain. Write each piece with its condition inside braces and the calculator draws exactly the right formula on each interval, breaking the graph where it jumps.

−4−224−220
Open in calculator
Three pieces: a line, a parabola and another line, joined continuously at x = −1 and with a jump at x = 1.

How to use the piecewise function grapher

  1. 1
    Write the function with its pieces in braces: y = {x < 0: -x, x^2} means −x when x < 0 and x² otherwise.
  2. 2
    Add as many pieces as you need. They are checked in order and the first true condition wins: y = {x < -1: -x - 1, x < 1: x^2 - 1, 2 - x}.
  3. 3
    Leave out the final value to make the function undefined elsewhere, or restrict any graph by appending a condition: y = x^2 {0 < x < 2}.
  4. 4
    To check whether the pieces meet, define the function as f(x) = {x < 1: x^2, 2 - x} and type f(1), or evaluate each piece at the breakpoint.

Writing piecewise functions

Each piece has the form condition: value, and pieces are separated by commas. Conditions can use <, ≤ (type <=), >, ≥ and compound ranges such as -1 < x < 1. A last entry without a condition is the “otherwise” value.

The textbook notation

f(x)=({(x<0): (−x), (x2)})

is read as “f(x) equals −x if x is negative, and x² otherwise”. That is the absolute value function on the left joined to a parabola on the right.

Continuity at the breakpoints

A piecewise function is continuous at a breakpoint when the pieces agree there. In the example above, at x = −1 the line gives −(−1) − 1 = 0 and the parabola gives (−1)² − 1 = 0, so the graph joins up. At x = 1 the parabola gives 0 but the last line gives 1, so the graph jumps.

The calculator samples each piece adaptively and breaks the curve at a jump rather than joining the two sides with a vertical line. It does not draw open and closed dots at the ends of pieces, so check your inequality signs to know which side includes the breakpoint.

Where piecewise functions show up

  • Tax brackets and tiered pricing, where the rate changes past a threshold.
  • Shipping costs and parking fees, which jump in steps.
  • Physics: a ball’s height before and after it lands, or a force that switches on at a time.
  • Absolute value, floor and sign functions, which are piecewise in disguise.

Examples to try

−4−224−220
Absolute value as pieces
y = {x < 0: -x, x}
Identical to |x|.
Open this example
123−110
A restricted domain
y = x^2 {0 < x < 2}
Only the part of the parabola with 0 < x < 2 is drawn.
Open this example
24685100
A tiered price
y = {x < 3: 2x, x < 6: 6 + x, 12}
£2 per item up to 3, £1 each after that, capped at £12.
Open this example

Frequently asked questions

How do I graph a piecewise function?
Type it with the pieces in braces, for example y = {x < 0: -x, x^2}. Each piece is condition: value, separated by commas, with an optional final value for “otherwise”.
How do I restrict the domain of a graph?
Append a condition in braces, for example y = x^2 {0 < x < 2}. The graph is drawn only where the condition holds.
Does it show open and closed dots at the breakpoints?
No. The graph breaks at jumps but does not mark the end points, so check the inequality signs to see which piece includes the breakpoint.
How do I check if a piecewise function is continuous?
Evaluate each neighbouring piece at the breakpoint. If they give the same value, the function is continuous there.

Related tools and guides

Try the piecewise function grapher

It opens instantly, with no account and nothing to install.

Open the calculator