Piecewise Function Calculator

Define a piecewise function \(f(x)\), evaluate it at a point, and see the exact LaTeX formula and a quick plot.

Optional. Letters only, used in the LaTeX (default: f).
Enter the x-value at which to evaluate your piecewise function.
Used if no condition matches. Leave blank for “undefined” outside your conditions.
x min x max
Range for the quick plot. Points outside defined pieces are left blank.
Number of x-samples to draw. Higher = smoother plot (slower).
Each piece needs an expression in x and a condition (first true condition wins).
Examples: expression 2*x+1, condition x < 0 or 0 <= x && x <= 5.
Supported operators: < <= > >= == !=, logical && or and, || or or.
Generated with . The typeset equation is shown on the right.
The nicely rendered equation will appear here.
Shows the piecewise definition and \(f(x_0)\) using your exact inputs.

Result

Evaluation
Selected piece and computed value at your \(x\).

Matched piece:
Condition:
Notes
  • “First true condition wins.” Order pieces from most specific to most general.
  • Use mathjs syntax: sin(x), abs(x), sqrt(x), constants pi, e.
  • Else expression is used if no condition is true; otherwise \(f(x)\) is undefined there.
  • Y Max caps the visible Y-axis high; leave blank for auto scale.

What is a Piecewise Function Calculator?

A Piecewise Function Calculator is a math tool that evaluates functions defined by multiple rules over different intervals of the input variable. Unlike single-formula functions, a piecewise function switches formulas at breakpoints (e.g., \(x=0\), \(x=1\), etc.). The calculator identifies which interval a given \(x\) belongs to, applies the matching formula, and returns the numerical result. Beyond evaluation, it checks continuity at breakpoints by comparing left- and right-hand limits, reports whether the function is continuous at a point, and—when rules are differentiable—computes derivatives on each interval. It can also integrate by summing definite integrals across subintervals. All formulas here are written in LaTeX so they display responsively when you load MathJax or math.js on your page.

About the Piecewise Function Calculator

Piecewise definitions model real behavior: taxes with brackets, absolute value, saturation/threshold systems, and many physics or economics laws. A typical form is:

\[ f(x)= \begin{cases} f_1(x), & x \in I_1 \\ f_2(x), & x \in I_2 \\ \vdots & \vdots \\ f_k(x), & x \in I_k \end{cases} \]

The calculator normalizes intervals (open/closed endpoints), handles missing powers, and applies exact comparisons at breakpoints. For continuity at \(x=c\), it checks whether

\[ \lim_{x\to c^-} f(x) \;=\; \lim_{x\to c^+} f(x) \;=\; f(c). \]

If derivatives are requested, it returns \(f'(x)\) on each interval and tests differentiability at \(c\) via matching one-sided derivatives. For integrals, it partitions the domain of integration at each breakpoint and sums the results. Results are presented step-by-step for clarity and verification.

How to Use this Piecewise Function Calculator

  1. Enter each rule \(f_i(x)\) and its interval \(I_i\) (e.g., \(x<1\), \(1\le x\le 3\), \(x>3\)).
  2. Choose your task: Evaluate, Limit/Continuity, Derivative, or Integral.
  3. Provide any points or bounds (e.g., evaluate at \(x=2\); limit at \(x=1\); integrate from \(a\) to \(b\)).
  4. Review the output: numeric result, interval used, and step-by-step math with LaTeX rendering.
  5. Adjust intervals or rules to explore alternate models or fix discontinuities.

Core Formulas (LaTeX for MathJax/math.js)

Piecewise definition: \[ f(x)=\sum_{i=1}^{k} f_i(x)\,\mathbf{1}_{I_i}(x), \qquad \mathbf{1}_{I_i}(x)= \begin{cases} 1,& x\in I_i\\[2pt] 0,& \text{otherwise} \end{cases} \]

Continuity at \(c\): \[ f \text{ is continuous at } c \iff \lim_{x\to c^-} f(x)=\lim_{x\to c^+} f(x)=f(c). \]

Derivative: \[ f'(x)= \begin{cases} f_1'(x), & x\in \operatorname{int}(I_1)\\ \vdots & \vdots\\ f_k'(x), & x\in \operatorname{int}(I_k) \end{cases} \quad\text{and}\quad f' \text{ at } c \text{ exists if } \lim_{x\to c^-} f'(x)=\lim_{x\to c^+} f'(x). \]

Definite integral across breakpoints: \[ \int_{a}^{b} f(x)\,dx = \sum_{i=1}^{k} \int_{[a,b]\cap I_i} f_i(x)\,dx. \]

Examples (Illustrative)

Example 1 — Evaluation & continuity

\[ f(x)= \begin{cases} x^2, & x<1\\ 2x+1, & x\ge 1 \end{cases} \] \(f(0)=0\), \(f(2)=5\). At \(x=1\): \(\lim_{x\to1^-}f=1\), \(\lim_{x\to1^+}f=3\), \(f(1)=3\). Not continuous at \(1\).

Example 2 — Derivative of \(|x|\)

\[ g(x)= \begin{cases} -x, & x<0\\ x, & x\ge 0 \end{cases} \Rightarrow g'(x)= \begin{cases} -1, & x<0\\ 1, & x>0 \end{cases} \] Derivative does not exist at \(0\) (one-sided derivatives differ).

Example 3 — Integral across intervals

\[ h(x)= \begin{cases} 1, & 0\le x<2\\ x, & 2\le x\le 4 \end{cases} \] \(\displaystyle \int_{0}^{4} h(x)\,dx=\int_{0}^{2}1\,dx+\int_{2}^{4}x\,dx=2+\frac{4^2-2^2}{2}=2+6=8\).

FAQs

What is a piecewise function?

A function defined by different formulas on different intervals of the domain with specified breakpoints.

How do I check continuity at a breakpoint?

Compare left and right limits and the defined value at the point; if all match, the function is continuous.

Can the calculator handle open and closed interval endpoints?

Yes. It respects \( <, \le, >, \ge \) so evaluation and continuity tests reflect endpoint choices.

When is synthetic notation useful (indicator/Heaviside)?

It compresses multiple rules into one expression for cleaner algebra, limits, and integrals.

How are derivatives handled at breakpoints?

It returns interval derivatives and checks one-sided derivatives at breakpoints to decide differentiability.

Can I integrate across multiple intervals automatically?

Yes. The tool splits the integral at each breakpoint and sums the results from all applicable intervals.

Does the calculator simplify absolute value functions?

Yes. It converts \(|x|\) into a two-piece definition and proceeds with evaluation, limits, or derivatives.

What happens if two intervals overlap?

The first matching rule is used; you should avoid overlaps or adjust ranges for an unambiguous definition.

Will the formulas render on mobile devices?

Yes. With MathJax or math.js loaded, LaTeX equations reflow responsively on phones and tablets.

More Math & Algebra Calculators