Piecewise Function Grapher
Plot piecewise functions using a JavaScript-style condition ? a : b expression.
About the Piecewise Function Grapher
Plot piecewise functions using a JavaScript-style condition ? a : b expression.
How to use this calculator
- Type your piecewise rule using a JavaScript-style conditional expression, such as x < 0 ? -x : x.
- Use comparisons like <, <=, >, and >= to split the domain into intervals.
- Enter each formula carefully so the graph changes at the right boundary point.
- Check the plotted graph to confirm each piece appears on the correct interval.
The formula explained
A piecewise expression has the form condition ? value_if_true : value_if_false. It computes one expression when the condition is true, and a different expression when the condition is false.
- x = the input value on the horizontal axis
- condition = a test such as x < 2 that decides which formula to use
- a = the expression returned when the condition is true
- b = the expression returned when the condition is false
Step by step method
- Identify the interval where each rule should apply.
- Write a condition that is true on that interval, for example x < 3.
- Put the matching formula after the ?, and the other formula after the :.
- Graph the expression and check that the break point is in the right place.
Worked example
Problem. Graph the piecewise function defined by f(x) = x + 1 for x < 2, and f(x) = 5 for x >= 2.
- Write the rule as x < 2 ? x + 1 : 5.
- For x = 1, the condition x < 2 is true, so f(1) = 1 + 1 = 2.
- For x = 2, the condition x < 2 is false, so f(2) = 5.
Answer. The graph follows the line y = x + 1 to the left of x = 2, then switches to the horizontal line y = 5 at and to the right of x = 2.
Tips and common mistakes
- Be careful with boundary points, because < and <= change whether the endpoint is included.
- If the graph looks wrong, check that your condition matches the interval exactly, especially near the switch point.
Frequently asked questions
How do I enter a piece?+
Use condition ? valueIfTrue : valueIfFalse, e.g. x<1 ? 1 : x.
Can I nest conditions?+
Yes, chain them: x<0 ? a : (x<2 ? b : c).
More Mathematics Tools
Explore related calculators in this category
Absolute Value Calculator
Calculate the absolute value of any number. Use this free calculator for fast, accurate answers, complete with the formula and a worked example.
Absolute Value Equation Solver
Solve equations of the form |ax + b| = c.
Adding Fractions Calculator
Add two fractions with step-by-step simplification.
One-Way ANOVA Calculator
Perform one-way ANOVA on multiple groups.
You Might Also Like
Popular tools from other categories
AC to DC Converter Calculator
Convert AC voltage to DC voltage for different rectifier configurations. Free online calculator with instant, step-by-step results.
Acid-Base Titration Calculator
Calculate concentration from titration data. Get quick, accurate results with this free online calculator, including formulas and worked examples.
ABV Calculator
Calculate alcohol by volume from original and final gravity. Free calculator with instant calculations, the underlying formula, and an easy-to-follow example.
Amortization Schedule Calculator - Free Online
Free Generate a complete amortization schedule. Step-by-step solutions and formulas included. Free, accurate results with step-by-step explanations.
Can't Find the Right Calculator?
Try our AI Math Solver, type any problem in plain English and get instant step-by-step solutions.