Evaluating Piecewise Functions

April 12, 2026

Problem

f(x) = {x² if x<0, 2x+1 if 0≤x<3, 7 if x≥3}. Evaluate at x=−2, 1, 5.

Explanation

What is a piecewise function?

A piecewise function uses different formulas on different intervals of xx. To evaluate it at a specific xx, you must first determine which piece applies (which interval contains your xx), then use that piece's formula.

The function

f(x)={x2if x<02x+1if 0x<37if x3f(x) = \begin{cases} x^2 & \text{if } x < 0 \\ 2x + 1 & \text{if } 0 \leq x < 3 \\ 7 & \text{if } x \geq 3 \end{cases}

Step-by-step evaluation

Evaluate f(2)f(-2)

Step 1 — Which piece? x=2x = -2. Is 2<0-2 < 0? Yes → use the first piece: f(x)=x2f(x) = x^2.

Step 2 — Compute: f(2)=(2)2=4f(-2) = (-2)^2 = 4.

Evaluate f(1)f(1)

Step 1 — Which piece? x=1x = 1. Is 1<01 < 0? No. Is 01<30 \leq 1 < 3? Yes → use the second piece: f(x)=2x+1f(x) = 2x + 1.

Step 2 — Compute: f(1)=2(1)+1=3f(1) = 2(1) + 1 = 3.

Evaluate f(5)f(5)

Step 1 — Which piece? x=5x = 5. Is 5<05 < 0? No. Is 05<30 \leq 5 < 3? No. Is 535 \geq 3? Yes → use the third piece: f(x)=7f(x) = 7.

Step 2 — Compute: f(5)=7f(5) = 7.

Graphing a piecewise function

Draw each piece only on its interval. Use an open circle (∘) where a piece does NOT include the endpoint, and a closed circle (●) where it does. At the boundaries (x=0x = 0 and x=3x = 3), check which piece "owns" the endpoint using the \leq vs << signs.

Checking continuity at boundaries

At x=0x = 0: Left limit (from piece 1) = 02=00^2 = 0. Right value (piece 2) = 2(0)+1=12(0) + 1 = 1. Since 010 \neq 1, there's a jump discontinuity at x=0x = 0.

At x=3x = 3: Left limit (piece 2) = 2(3)+1=72(3) + 1 = 7. Right value (piece 3) = 77. Since 7=77 = 7, the function is continuous at x=3x = 3.

Try it in the visualization

Drag the xx-slider across the domain. The graph highlights which piece is active, and the f(x)f(x) value updates. Open and closed dots at boundaries show the transition points.

Interactive Visualization

Parameters

1.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Evaluating Piecewise Functions | MathSpin