Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Function Analysis

Piecewise and Absolute Value Functions

Define and graph piecewise functions, step functions and absolute value functions, solve absolute value equations, and model real situations in Python.

Real situations rarely follow one formula for ever. A taxi fare has a flat fee and then a rate. A phone plan changes price above a data limit. Income tax uses different rates in different bands. A piecewise function captures this by using a different rule on each part of its domain. The absolute value function, which you met earlier as distance, turns out to be a piecewise function in disguise.

Piecewise functions

A piecewise function is written with a brace and conditions:

Text
f(x) = x + 2     if x < 1
       3         if x = 1
       xยฒ        if x > 1

To evaluate f(a), find which condition a satisfies and use that rule only. So f(-2) = 0, f(1) = 3, f(3) = 9.

To graph it, draw each piece on its own interval. At each boundary, mark an open dot where the endpoint is not included and a filled dot where it is. Here the left piece approaches the point (1, 3) from the left, the middle rule places a filled dot at (1, 3), and the right piece starts at (1, 1) with an open dot. The graph jumps at x = 1.

The conditions must not overlap, or the function would give two outputs for one input. Together they should cover the whole domain you intend.

Python Evaluate and plot a piecewise function

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Absolute value as a piecewise function

The absolute value is defined by two cases:

Text
|x| = x     if x โ‰ฅ 0
      -x    if x < 0

Its graph is a V with vertex at the origin. Using the transformations from earlier, y = a|x - h| + k is a V with vertex at (h, k), opening up if a > 0 and down if a < 0, with slopes ยฑa.

Example: f(x) = 2|x + 1| - 3 has vertex (-1, -3), y-intercept f(0) = 2 - 3 = -1, and x-intercepts where |x + 1| = 3/2, i.e. x = 1/2 and x = -5/2.

To rewrite an absolute value expression piecewise, find where the inside is zero and split there: |2x - 4| equals 2x - 4 for x โ‰ฅ 2 and -(2x - 4) = 4 - 2x for x < 2.

Absolute value equations and inequalities

  • |A| = k (with k > 0): A = k or A = -k.
  • |A| < k: -k < A < k. (One connected interval.)
  • |A| > k: A < -k or A > k. (Two pieces.)

Solve |3x - 2| โ‰ค 7: -7 โ‰ค 3x - 2 โ‰ค 7, so -5 โ‰ค 3x โ‰ค 9, so -5/3 โ‰ค x โ‰ค 3. In interval notation, [-5/3, 3].

Python Check an absolute value solution set

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step functions

A step function is constant on pieces, so its graph looks like stairs. The floor function โŒŠxโŒ‹ gives the largest integer not greater than x: โŒŠ2.7โŒ‹ = 2, โŒŠ-1.2โŒ‹ = -2. The ceiling โŒˆxโŒ‰ gives the smallest integer not less than x. Parking charges that round up to the next hour use a ceiling.

Modeling with piecewise functions

Suppose a courier charges 5 dollars for packages up to 1 kg, then 3 dollars per additional kilogram or part of one. For weight w kg (with w > 0):

Text
cost(w) = 5                     if 0 < w โ‰ค 1
          5 + 3ยทceil(w - 1)     if w > 1

A 2.3 kg package: ceil(1.3) = 2, so the cost is 5 + 6 = 11 dollars.

Python A piecewise courier price model

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When graphing a step function, use filled and open dots to show exactly where the value jumps. The jump is a discontinuity, an idea you meet again in the limits chapter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where is the vertex of y = 2|x + 1| - 3?

    In a|x - h| + k the vertex is (h, k). Here h = -1 and k = -3.
  2. 2. Solve |x - 2| < 3.

    -3 < x - 2 < 3 gives -1 < x < 5.
  3. 3. What is โŒŠ-1.2โŒ‹?

    The floor is the largest integer not greater than -1.2, which is -2.
  4. 4. What must be true of the conditions in a piecewise function?

    Otherwise an input could have two outputs (or none), so it would not be a function.

Summary

  • A piecewise function uses a different rule on each part of its domain; use open and filled dots at boundaries.
  • |x| is piecewise: x for x โ‰ฅ 0, -x for x < 0; a|x - h| + k has vertex (h, k).
  • |A| < k gives one interval; |A| > k gives two.
  • Step functions such as floor and ceiling model stair-like situations.

Next: Quadratic Functions and Vertex Form