Free lesson

Every lesson is free, no account needed. Make a free account to save your progress.

Live classGet practice + mocks
  1. Home
  2. Lesson Library
  3. Piecewise functions
UPCAT Math Review · Functions

Piecewise Functions

One function, two rules, and a condition that says which one you are in.

Given

f(x) = 2x + 1  if x < 2

f(x) = x² − 3  if x ≥ 2

Find f(2).

The condition chooses the rule.

Test the input first. Only then do any arithmetic.

InputWhich condition holdsRule to use
x = 00 < 2 ✓2x + 1
x = 22 ≥ 2 ✓x² − 3
x = 55 ≥ 2 ✓x² − 3

A piecewise function is still one function: every input gets exactly one output. The conditions are written so that they never overlap and never leave a gap.

Substitute into the chosen rule only.

f(0) = 2(0) + 1

0 is below 2

= 1

the linear piece

f(5) = 5² − 3

5 is at or above 2

= 22

the quadratic piece

Never both

Running the input through each rule and adding, or picking whichever looks nicer, are both ways of answering a question nobody asked. One input, one condition, one rule.

The boundary belongs to one side.

Here x ≥ 2 owns the number 2, because that is where the “or equal to” sits.

f(2) = 2² − 3

the ≥ rule wins

= 1

not 5

2(2) + 1 = 5

what the other rule would have given

f(0) = 1 · f(2) = 1 · f(5) = 22

Read the inequality signs before anything else

Swap < and ≤ and the value at the boundary changes completely. It is the one number the question is guaranteed to ask about, and 5 will be sitting there in the choices.

Graph each piece only where it lives.

y = 2x + 1 y = x² − 3 (2, 5) open (2, 1) filled x = 2

filled circle ●

the point is included

from ≤ or ≥

open circle ○

the curve stops just short

from < or >

The jump from 5 down to 1 at x = 2 is real — the graph is broken there. Only one of the two circles is filled, so the function still gives one answer.

Where they actually turn up.

Fares, tax brackets, parking, delivery charges — anything priced in bands.

₱40 for the first 3 hours

C(t) = 40 for 0 < t ≤ 3

₱15 for each hour after

C(t) = 40 + 15(t − 3) for t > 3

C(5) = 40 + 15(2)

two hours past the band

= ₱70

not 15 × 5

The (t − 3) is the whole trick

The extra charge applies to the hours beyond the first three, so the subtraction has to be inside the bracket. Charging 15t would bill the flat-rate hours twice.

“Or any part of an hour” rounds up.

A lot charges ₱30 for the first hour or any part of it, then ₱12 for each additional hour or part of an hour. A car stays 4 hours 20 minutes. Then: a driver paid ₱90 — what is the longest stay?

4 h 20 min − 1 h = 3 h 20 min

time beyond the flat band

3 h 20 min → 4 chargeable hours

the 20 minutes start a whole new hour

30 + 12 × 4 = ₱78

not 30 + 12 × 3⅓ = ₱70

Backwards: (90 − 30) ÷ 12 = 5 extra hours

take off the flat band first

1 + 5 = 6 hours at most

one minute more starts a 6th extra hour

Two traps in one fare

Charging the fraction exactly (3⅓ hours) undercharges, and dividing ₱90 by ₱12 forgets the flat first band. Subtract the band, round the rest up.

Variations: three pieces with a negative input, and f(f(x)).

Three pieces, a negative input. Let f(x) = 1 − x² if x < −1, f(x) = 3 if −1 ≤ x ≤ 2, and f(x) = 2x − 1 if x > 2. Find f(−3), f(2) and f(2.5).

f(−3) = 1 − (−3)² = 1 − 9 = −8

−3 < −1: first piece; square in brackets

f(2) = 3

−1 ≤ 2 ≤ 2: the middle piece owns 2

f(2.5) = 2(2.5) − 1 = 4

2.5 > 2: last piece

What is different: a constant piece ignores x completely, and a middle condition has two ends to test.

1 − x² at x = −3 is not 10

Squaring comes before the minus in front: 1 − (−3)² = 1 − 9 = −8. Writing 1 + 9 = 10 lets the minus in front cancel the minus of −3, as if the square were not there.

A function of a function. Let f(x) = x² if x < 3, and f(x) = 10 − 2x if x ≥ 3. Find f(f(2)).

f(2) = 2² = 4

inside first: 2 < 3, the square piece

f(f(2)) = f(4)

the output becomes the new input

f(4) = 10 − 2(4) = 2

4 ≥ 3: now the OTHER piece

What is different: the condition is tested twice, once per input. Using x² again would give 16, the wrong answer.

Solving f(x) = a number: solve each piece, then check its condition.

Let f(x) = x² − 4 if x ≤ 1, and f(x) = 2x + 3 if x > 1. Solve f(x) = 5.

x² − 4 = 5 → x = 3 or x = −3

first piece

keep −3, reject 3

this piece only lives at x ≤ 1

2x + 3 = 5 → x = 1

second piece

reject 1

this piece needs x > 1, and 1 is not

x = −3 only

one solution, not three

Check: f(−3) = 9 − 4 = 5 ✓, while f(1) = 1 − 4 = −3 and f(3) = 2(3) + 3 = 9. The same habit answers “how many solutions” and f(f(x)) questions: work inside out, choosing the rule fresh at every step.

A letter inside a rule works the same way. Let h(x) = mx − 2 if x < 1, and h(x) = x² + m if x ≥ 1, with h(1) = 5. The input 1 lives in the x ≥ 1 piece, so 1 + m = 5 and m = 4. Now use m in the other piece: h(−2) = 4(−2) − 2 = −10.

On the exam

The boundary value, a fare with “or any part of”, and “how many x give f(x) = c” are the favourites. For each candidate answer, spend two seconds asking “which condition does this x satisfy?” — that alone kills most wrong choices.

Check: creep up on the boundary.

Values just below 2 should follow the line; values at 2 and above should follow the parabola.

x = 1.9 2(1.9) + 1 = 4.8 heading for 5
x = 2 2² − 3 = 1 the jump ✓
x = 2.1 2.1² − 3 = 1.41 rising from 1 ✓

Remember the flow

Test the condition · Use that rule only · Watch the boundary

Open circle for a strict inequality, filled for “or equal to”.
Now you try

Practice problem

Given g(x) = x² + 1 if x < −1, and 4 − 3x if x ≥ −1

Find g(−1) + g(−3).