📘 CodingMarble Learn

Piecewise, Absolute Value and Step Functions

A piecewise function uses different rules on different parts of its domain. To evaluate it, first find which interval x is in, then use only that rule. On the graph, a closed dot ● means the end point is included (≤ or ≥) and an open dot ○ means it is not (< or >). The absolute value function y = |x| is piecewise: −x for x < 0 and x for x ≥ 0, giving a V with vertex (0, 0); y = a|x − h| + k moves the vertex to (h, k). Step functions such as ⌊x⌋, ⌈x⌉ or a parking fee are flat pieces that jump at whole numbers.

🎬 Step-by-step story

  1. Some rules change halfway. A function can use one rule on the left part of the x-axis and another rule on the right. A wall at the split point shows where the rule changes.
  2. To find f(x), first ask: which part is x in? Then put x into that one rule only. Watch three values being worked out.
  3. At a split point we must say which rule owns it. A closed dot means the point is included. An open dot means it is not. When the two pieces do not meet, the graph jumps.
  4. The absolute value |x| is a piecewise function: it makes negative numbers positive. Its graph is a V. Changing h and k slides the V to a new vertex (h, k).
  5. A step function stays flat, then jumps. Parking that charges for every started hour is one. Each step has an open dot at one end and a closed dot at the other.
  6. Your turn. Move a, h and k to change the V. Slide x and read f(x) from the green dot.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why can't both pieces include the break point?

Then one x would have two outputs, and a function must give exactly one. One piece gets the closed dot, the other gets the open dot.

Do I put x into both rules and choose?

No. First check the condition, then use only that one rule. The 3D shows the green dot moving to the right piece for each x.

Is |x| really a piecewise function?

Yes: −x on the left of 0 and x on the right. The two coloured halves of the V are these two pieces.

Why does |x − 2| move the V to the right, not the left?

The corner is where x − 2 = 0, which is x = 2. So the vertex moves to x = 2, which is right of 0.

Why is 1.5 hours of parking charged as 2 hours?

The fee uses the ceiling ⌈t⌉: any started hour counts as a full hour. The 1.5 point lies on the step at height 2.

What changes when a is negative?

The V flips and opens downward, so the vertex becomes the highest point. Try a = −1 in free play.

What is a piecewise function?

A piecewise function is one function built from two or more rules. Each rule works on its own interval (a part of the x-axis). The intervals must not overlap, so every x gets exactly one output.

We write it with a big brace:

f(x) = x + 2, if x < 1
f(x) = 5 − x, if x ≥ 1

The number where the rule changes (here x = 1) is called the break point or split point.

Evaluating a piecewise function

Two steps, always in this order:

  1. Where? Look at the conditions and find the interval that contains x.
  2. What? Put x into that rule only.

For the function above: f(−2): −2 < 1, so use x + 2 → 0. f(1): 1 ≥ 1, so use 5 − x → 4. f(3): 3 ≥ 1 → 2.

Be careful at the break point: check whether the sign is < or ≤.

Graphing: open and closed dots, jumps

Graph each rule only over its own interval, like cutting a piece from a full line. At each end point:

If the pieces meet at the same height, the graph is continuous (no gap). If they end at different heights, the graph has a jump. Each x may have only one closed dot above it, otherwise it is not a function (vertical line test).

Domain and range

Read the domain from the intervals and the range from the heights the pieces reach, using the dots to decide if an end value is included.

Absolute value functions

The absolute value |x| is the distance of x from 0, so it is never negative: |−3| = 3, |3| = 3.

As a piecewise function: |x| = −x if x < 0, and x if x ≥ 0. The graph is a V with its corner (vertex) at (0, 0).

Transformations: y = a|x − h| + k

The vertex is (h, k). To solve |x − 2| = 3, split it: x − 2 = 3 or x − 2 = −3, so x = 5 or x = −1.

Step functions

A step function is a piecewise function whose pieces are flat (constant). Its graph looks like stairs.

Real step functions: postage by weight band, parking per started hour, mobile plans by GB used. Parking at ₹20 per started hour is fee = 20⌈t⌉ for t > 0.

Try it: a fare table at home

Pick a real tariff, such as a taxi or auto fare (fixed charge for the first 2 km, then a rate per km) or your home electricity slab rates. Write it as a piecewise function. Make a table for 5 values, plot the points on squared paper and mark open and closed dots at the break points. Then check one bill with your rule. In the 3D, set the V in step 6 and predict f(x) before sliding x.

Key formulas and definitions

Worked examples

1. f(x) = 3x if x < 2, and x + 4 if x ≥ 2. Find f(0), f(2) and f(5).

f(0): 0 < 2 → 3·0 = 0. f(2): 2 ≥ 2 → 2 + 4 = 6. f(5): 5 ≥ 2 → 5 + 4 = 9.

2. g(x) = 1 if x ≤ 0, and −x if x > 0. Find g(0) and g(0.5).

g(0): 0 ≤ 0 → 1. g(0.5): 0.5 > 0 → −0.5.

3. Find the vertex and the direction of y = −2|x + 1| + 3.

Write it as −2|x − (−1)| + 3, so h = −1, k = 3. Vertex (−1, 3). a = −2 < 0, so the V opens downward and (−1, 3) is the highest point.

4. Is f(x) = x + 1 (x < 2), 3 (x ≥ 2) continuous at x = 2?

Left piece ends at 2 + 1 = 3 (open dot). Right piece starts at 3 (closed dot). Same height, so there is no jump: it is continuous at x = 2.

5. Solve |2x − 1| = 7.

Split: 2x − 1 = 7 → x = 4, or 2x − 1 = −7 → x = −3. Check: |7| = 7, |−7| = 7. Answer x = 4 or x = −3.

6. Electricity costs ₹5 per unit for the first 100 units and ₹7 per unit after that. Write the bill B(u) and find B(160).

B(u) = 5u if 0 ≤ u ≤ 100; B(u) = 500 + 7(u − 100) if u > 100. B(160) = 500 + 7·60 = 500 + 420 = ₹920.

7. Parking costs ₹20 per started hour. Find the fee for 2 h 10 min and for exactly 3 h.

Fee = 20⌈t⌉. 2 h 10 min ≈ 2.17 h → ⌈2.17⌉ = 3 → ₹60. Exactly 3 h → ⌈3⌉ = 3 → ₹60.

Common mistakes

Practice quiz

1. f(x) = 2x if x < 3; 10 if x ≥ 3. What is f(3)?
2. An open dot at the end of a piece means:
3. The vertex of y = |x − 4| − 2 is:
4. ⌊3.9⌋ equals:
5. Which graph shape does y = |x| have?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a piecewise function in simple words?

A function that uses different formulas for different ranges of x, like a fare that changes after a certain distance.

How do you know if a dot is open or closed?

Look at the inequality sign: < or > means open (not included); ≤ or ≥ means closed (included).

What is the difference between floor and ceiling?

Floor ⌊x⌋ rounds down to the integer at or below x; ceiling ⌈x⌉ rounds up to the integer at or above x.

Where this is taught

USA (Common Core, NGSS, AP)Grade 9Quadratic functions and modeling

Learn first

Learn next

Related lessons

All Maths lessons