Quick answer: A piecewise function grapher draws a function that uses different rules on different intervals. Enter each rule, choose where it applies, and this piecewise function grapher plots every piece only on its own interval, marking each endpoint with an open circle when the boundary is excluded and a closed circle when it is included — so you can graph piecewise functions online and read off values with confidence.
How to use this piecewise function grapher
Step 1 — Write the first rule. In the Piece 1 box, type the expression exactly as you would on paper, using ^ for powers and the supported function names: sqrt, abs, sin, cos, tan, log, ln and exp. The constants pi and e are available, and implicit multiplication such as 2x or 3sin(x) is understood — the same typing conventions as the FreeSoftis Derivative Calculator, because both tools read expressions with their own small parser rather than trusting raw input.
Step 2 — Choose where the rule applies. Under the expression, pick the domain condition: x less than a, x less than or equal to a, between two bounds with either strict or inclusive ends, x greater than a, x greater than or equal to a, or all x. Type the bound values into the a and b boxes that appear. The strictness you choose here is not decoration — it decides whether the endpoint of that piece is drawn as an open or a closed circle, and whether the evaluator counts that x value as belonging to the piece.
Step 3 — Add the remaining pieces. Pieces 2, 3 and 4 work the same way. Leave a piece blank and it is ignored. The pre-filled example — x + 2 for x less than 0, and x^2 for x greater than or equal to 0 — is the worked example checked by hand further down this guide, so you can verify the tool against arithmetic you can do yourself before trusting it with your own function.
Step 4 — Read the graph, then evaluate. Each piece is drawn in its own colour, only over the interval where its condition holds, and the legend under the graph repeats each rule with its condition. Type any x into the evaluator and the tool reports which piece applies, the value of f(x), or undefined when no piece covers that x. Below the graph, a table of sample points lists f(x) at integer x values across the window, which is the fastest way to spot a gap or an overlap you did not intend.
Step 5 — Save your work. Download saves the graph as a PNG with its axes, grid and endpoint circles. Copy gives you a text summary of the pieces, conditions and values for your notes or assignment. Nothing is uploaded at any step.
What is a piecewise function?
A piecewise function is a single function whose rule changes depending on where x sits. Most functions you meet early on have one formula that works everywhere: f(x) = x^2 squares any number you hand it. A piecewise function instead carries a small list of formulas, each labelled with the part of the domain it governs. Formally it is still one function — every x in the domain gets at most one output — but the recipe for producing that output is chosen by a test on x first.
The notation stacks the rules in a brace, with the condition written after each rule. Read it top to bottom as a set of instructions: if the first condition is true, use the first rule; otherwise check the next. That reading order matters for how this piecewise function calculator evaluates a value when conditions overlap: it applies the first piece whose condition is true, and tells you that it did so.
Piecewise definitions are not a classroom invention. They appear whenever a real rule genuinely changes at a threshold: income tax applies one rate up to a bracket boundary and a different rate above it; postage steps up at weight thresholds. The absolute value function is simply x when x is not negative and minus x when it is — which is why abs is built into this grapher, and why you can also write it out as two pieces yourself.
Two ideas decide almost every question about a piecewise function. The first is coverage: any x claimed by no piece is outside the domain, and the function is undefined there. The second is agreement at the seams: where two pieces meet, do they produce the same value, and which of them owns the boundary point? The endpoint circles on the graph answer the second question at a glance.
Worked example: x + 2 and x^2, checked by hand
The example loaded when this page opens is f(x) = x + 2 for x less than 0, and f(x) = x^2 for x greater than or equal to 0. It is worth checking by hand, because it contains the one situation students most often get wrong: a boundary where the two rules disagree.
Take x = −1. The first condition, x less than 0, is true, so the first rule applies: f(−1) = −1 + 2 = 1. The graph shows the line x + 2 passing through (−1, 1) on its way up to the right. Take x = 2. The first condition is false and the second, x greater than or equal to 0, is true, so f(2) = 2^2 = 4, a point on the parabola. Both of those are routine. The interesting value is x = 0 itself.
At x = 0, the first rule would give 0 + 2 = 2 — but it does not apply, because its condition is strict: 0 is not less than 0. The graph therefore marks the point (0, 2) with an open circle: the line arrives there, but the point is not part of the graph. The second rule does apply at 0, because its condition is inclusive, and it gives 0^2 = 0. So f(0) = 0, marked with a closed circle at (0, 0). Type 0, −1 and 2 into the evaluator above and you will get exactly these answers: 0 from piece 2, 1 from piece 1, and 4 from piece 2.
Notice what happens at the seam: coming from the left, values approach 2; at the seam itself the value is 0; from the right, values rise from 0. That is a jump discontinuity, and the pair of circles — open at height 2, closed at height 0 — is the standard way to draw it honestly. A grapher that joined the two curves with a vertical line would be claiming values the function does not have.
Open and closed endpoints: the rules
One principle generates every endpoint marker: a boundary point belongs to a piece exactly when that piece's condition is true at the boundary. Strict inequalities — plain less than and greater than — are false at their own boundary, so the point is excluded and drawn open. Inclusive inequalities — less than or equal to, greater than or equal to — are true at their boundary, so the point is included and drawn closed. This grapher does not guess: it tests the actual condition at the actual boundary value, so the circle it draws is the condition you chose, rendered visible.
| Condition on the piece | At the lower bound | At the upper bound | Circle drawn |
|---|---|---|---|
| x < a | No lower bound — the piece extends to the left | a is not included | Open circle at (a, f(a)) |
| x ≤ a | No lower bound — the piece extends to the left | a is included | Closed circle at (a, f(a)) |
| a < x < b | a is not included | b is not included | Open circles at both ends |
| a ≤ x ≤ b | a is included | b is included | Closed circles at both ends |
| x > a | a is not included | No upper bound — the piece extends to the right | Open circle at (a, f(a)) |
| x ≥ a | a is included | No upper bound — the piece extends to the right | Closed circle at (a, f(a)) |
| All x | No bound | No bound | No endpoint circle |
Two subtleties are worth knowing. First, an open circle is drawn at the height the piece's own rule would give at the boundary, even though the piece does not own that x: in the worked example it sits at (0, 2) because x + 2 equals 2 at x = 0 — it shows where that piece was heading. Second, two pieces can legitimately mark the same boundary at different heights, or at the same height: if both rules agree at the seam and one includes it, the graph is continuous there. Trouble only starts when two pieces claim a whole interval, not just a point, with different values.
How to evaluate a piecewise function at a point
Evaluating a piecewise function is a two-step job: first find the right rule, then do the arithmetic. Students who go wrong almost always skip the first step and substitute into whichever rule catches their eye. The disciplined method is to test the x value against each condition, in order, until one is true — and only then substitute into that rule. That is exactly the procedure the evaluator on this page automates, and it reports which piece it used so you can check its choice against your own.
Three outcomes are possible. The common one: exactly one condition is true, you substitute, and you are done. The second: no condition is true, and the correct answer is that the function is undefined at that x — a legitimate answer, and the one this calculator gives rather than inventing a value. The third: more than one condition is true. At a single shared endpoint where both rules agree, that is harmless; across an interval it means the definition is ambiguous as written, and the right fix is to rewrite the conditions so they partition the domain instead of overlapping.
Boundary values deserve a deliberate test, not a glance. When x is exactly a bound, strict and inclusive conditions part company, and the question usually turns on it — as f(0) did in the worked example. A good habit: say the condition out loud with the number in it. Zero is less than zero is false; zero is greater than or equal to zero is true. The arithmetic after that is the easy part.
Gaps, jumps and continuity
A piecewise graph can fail to join up in three distinct ways, and the graph shows each one differently. A gap is an interval no piece covers: the graph simply stops and starts again later, and the function is undefined throughout the missing stretch. A jump happens where two pieces meet at a boundary but at different heights: both sides exist, the function has a value at the boundary itself (shown by whichever closed circle is present), but the two sides do not connect. A hole is the single-point version: the pieces agree on the height at a boundary, but neither includes the point, leaving an open circle with nothing filled in — the function is undefined at exactly that one x.
Continuity at a seam needs three things at once: the left-hand piece must approach some height, the right-hand piece must approach the same height, and the function value at the seam must equal that height. Try the variants in the grapher: change the worked example's second condition to x greater than 0 and f(0) becomes undefined; change the first piece to include 0 and f(0) becomes 2 while the right side still rises from 0 — still a jump, with the value now on the upper shelf.
This is also where the drawing method matters. Because each piece is plotted only over its own interval, as its own segment, this grapher never paints a vertical connector across a jump or a line across a gap. Some quick plotting tools join the last point of one piece to the first point of the next, which invents values the function does not have. If you see a vertical line at a seam in any graph, treat it as a drawing artefact, not mathematics.
Where piecewise functions show up in real life
Any rule with a threshold in it is a piecewise function waiting to be written down. Electricity tariffs charge one rate per unit up to a usage level and a higher rate beyond it. Overtime pay is the hourly rate up to 40 hours and time-and-a-half after. Shipping costs step up at weight bands. In each case the honest model is a list of formulas with conditions — and the graph, with its steps and jumps, is a picture of the price list itself.
In mathematics courses, the same structure covers several named functions. The absolute value function is two pieces. The greatest-integer or floor function is an infinite staircase of constant pieces — more than this grapher's four, but its first few steps can be modelled with constant pieces such as 0, 1 and 2 on successive unit intervals. Sign functions, saturation limits in engineering (a sensor that reads truly up to its maximum and then flat-lines), and tax-bracket calculations all share the shape.
Piecewise modelling is also an approximation technique: a curve that is hard to describe with one formula can be approximated by straight pieces on successive intervals — the idea behind linear interpolation and, in more advanced work, splines. For the single-formula side of graphing, the Scatter Plot Maker covers data points and regression lines, and the Slope Calculator covers the gradient of any one straight piece.
Common mistakes when you graph piecewise functions
Mistake one: drawing each rule across the whole window. The rule x + 2 exists only for x less than 0; drawing its full line and the full parabola together pictures two functions, not one. The fix is the procedure above: draw lightly, keep only the interval that belongs, erase the rest. This grapher enforces it by testing every plotted point against the piece's condition.
Mistake two: putting the closed circle on the wrong piece. At a jump, the filled circle belongs to the piece whose condition includes the boundary — the inclusive one — regardless of which piece is drawn first or which looks more important. In the worked example the closed circle is at (0, 0), on the parabola, not at (0, 2) on the line. Getting this backwards changes f(0) itself, which is usually the exact thing the question is testing.
Mistake three: joining the pieces. A vertical segment at a seam, or a line drawn across a gap, claims the function takes every value in between. It does not. Pieces are separate segments; where they do not meet, the graph should show that they do not meet.
Mistake four: conditions that overlap or leave holes by accident. Ending one piece at x less than 2 and starting the next at x greater than 3 leaves 2 to 3 undefined; starting the next at x greater than or equal to 1 double-claims 1 to 2. The sample points table is the quick audit: scan it for unexpected undefined entries, and evaluate both sides of every seam. Mistake five is quieter: forgetting that log means base 10 here while ln is the natural logarithm, and that the trigonometric functions expect radians — a piece like sin(x) drawn over degrees-sized windows looks almost flat, which is a units problem, not a grapher problem.
Honest limits: sampled plotting and supported expressions
The graph is a sampled plot, and this page will not pretend otherwise. To draw a piece, the grapher evaluates its expression at 401 evenly spaced sample points across the viewing window and joins consecutive samples that lie in the same continuous stretch. For the smooth rules this tool supports, that is indistinguishable from the true curve at screen resolution. But sampling has known edges: a very narrow spike between two sample points could be under-drawn, and a function that oscillates faster than the sampling, such as sin(200x) on a wide window, will show aliasing — a false, slower wobble. Narrow the window and the picture corrects itself, because the same 401 samples then cover a smaller stretch.
Two parts of the tool do not depend on sampling at all. Endpoint circles are placed by evaluating the piece's expression at the exact boundary value and testing the piece's actual condition there. The evaluator likewise substitutes your exact x into the parsed expression. Both use ordinary double-precision floating point, so results are as accurate as the arithmetic in any standard calculator — which also means a value like 0.1 + 0.2 carries the usual floating-point rounding, invisible at the four decimal places this tool displays.
The expression language is deliberately bounded. Supported: numbers, x, pi, e, the operators + − * / ^ and parentheses, implicit multiplication, and the functions sqrt, abs, sin, cos, tan, log (base 10), ln and exp. Not supported: other variables, other functions such as sec or sinh, factorials, and nested piecewise definitions. Input outside the set is rejected with a message naming the problem token, never silently reinterpreted — the parser is a small recursive-descent parser written for this site, and user input is never passed to eval or any equivalent. Up to four pieces can be graphed at once. If your function needs more, graph it in two passes of four and compare the seams by hand.
Sources and References
The definitions, endpoint conventions and continuity tests in this guide follow the standard textbook treatment of piecewise-defined functions in the sources below. Every worked number on this page — f(−1) = 1, f(0) = 0, f(2) = 4, and the open circle at (0, 2) — was produced by this page's own parser and checked by hand, so you can reproduce each one in the tool above.
- Wikipedia — Piecewise function (definition, notation and standard examples)
- Wolfram MathWorld — Piecewise Function (formal definition and special piecewise functions)
- OpenStax, Algebra and Trigonometry 2e — Domain and Range (piecewise-defined functions and their graphs)
- LibreTexts — Domain and Range (evaluating and graphing piecewise functions, open and closed endpoints)
- Khan Academy — Introduction to Piecewise Functions (worked graphs and evaluation)
- Paul's Online Math Notes, Lamar University — Continuity (what happens at the boundary points of piecewise functions)
- Cuemath — Piecewise Function (graphing steps, domain and range, examples)