Page 2.7: Piecewise Defined Functions

Piecewise defined functions are used in many real-world phenomena (e.g. postal rates and income tax formulas) are modeled by such functions. It is important that we are familiar with them and know how to evaluate them. Consider the absolute value function \(f(x)=\left|x\right|\). The domain is real numbers and the range is values greater than or equal to 0. If we input 0 or any positive value, the output is the same value as the input (\(f(0)=\left|0\right|=0\), \(f(3)=\left|3\right|=3\), \(f(7.2)=\left|7.2\right|=7.2\), . ). \(f(x) = x\) if \(x \ge 0\) If we input a negative value the sign of the output must change from negative to positive (\(f(-1)=\left|-1\right|=1\), \(f(-4.5)=\left|-4.5\right|=4.5\), . ). \(f(x) = -x\) if \(x < 0\), since multiplying a negative value by -1 makes it positive. Since this requires two different processes or pieces, the absolute value function is often called the most basic piecewise defined function.

Piecewise Function

A piecewise function is a function in which the formula used depends upon the domain the input lies in. We notate this idea like: \[f(x) = \begin \text \\ \text \\ \text \end\nonumber \] Note that piecewise defined functions are not rescricted to 3 formulas, they may contain 2 or more.

Example \(\PageIndex\)

A museum charges $5 per person for a guided tour with a group of 1 to 9 people, or a fixed $50 fee for 10 or more people in the group. Set up a function relating the number of people, \(n\), to the cost, \(C\). Solution To set up this function, two different formulas would be needed. C = 5n would work for n values under 10, and C = 50 would work for values of n ten or greater. Notating this: \[C(n) = \begin 5n & \text \\ 50 &\text n \ge 10\end\nonumber \]

Example \(\PageIndex\)

  1. \(f(0)\)
  2. \(f(1)\)
  3. \(f(3)\)

Solution

  1. Since the input is 0, we input into the top formula, \(x+6\). So, \(f(0)=0+6=6\)
  2. Since the input is 1, we input into the top formula, \(x+6\). So, \(f(1)=1+6=7\)
  3. Since the input is 3 we input into the bottom formula, \(3-x^2\). So, \(f(0)=0+6=6\)

Example \(\PageIndex\)

A cell phone company uses the function below to determine the cost, C, in dollars for g gigabytes of data transfer.

Find the cost of using 1.5 gigabytes of data, and the cost of using 4 gigabytes of data.

Solution

To find the cost of using 1.5 gigabytes of data, \(C(1.5)\), we first look to see which piece of domain our input falls in. Since 1.5 is less than 2, we use the first formula, giving \(C(1.5)\) = $25.

The find the cost of using 4 gigabytes of data, \(C(4)\), we see that our input of 4 is greater than 2, so we’ll use the second formula. \(C(4)\) = 25 + 10(4 - 2) = $45.

Example \(\PageIndex\)

The height \(h\) in feet of a model rocket above the ground \(t\) seconds after lift-off is given by

\[ h(t) = \left\< \begin -5t^2 + 100t, & \mbox & 0 \leq t \leq 20 \\ 0, & \mbox & t > 20 \\ \end \right.\nonumber\]

  1. Find and interpret \(h(10)\) and \(h(60)\).
  2. Solve \(h(t) = 375\) and interpret your answers.

Solution

  1. We first note that the independent variable here is \(t\), chosen because it represents time. Secondly, the function is broken up into two rules: one formula for values of \(t\) between \(0\) and \(20\) inclusive, and another for values of \(t\) greater than 20. Since \(t=10\) satisfies the inequality \(0 \leq t \leq 20\), we use the first formula listed, \(h(t) = -5t^2 + 100t\), to find \(h(10)\). We get \(h(10) = -5(10)^2 + 100(10) = 500\). Since \(t\) represents the number of seconds since lift-off and \(h(t)\) is the height above the ground in feet, the equation \(h(10) = 500\) means that \(10\) seconds after lift-off, the model rocket is \(500\) feet above the ground. To find \(h(60)\), we note that \(t=60\) satisfies \(t > 20\), so we use the rule \(h(t) = 0\). This function returns a value of \(0\) regardless of what value is substituted in for \(t\), so \(h(60) = 0\). This means that \(60\) seconds after lift-off, the rocket is \(0\) feet above the ground; in other words, a minute after lift-off, the rocket has already returned to Earth.
  2. Since the function \(h\) is defined in pieces, we need to solve \(h(t) = 375\) in pieces. For \(0 \leq t \leq 20\), \(h(t) = -5t^2 + 100t\), so for these values of \(t\), we solve \(-5t^2 + 100t = 375\). Rearranging terms, we get \(5t^2 - 100t + 375 = 0\), and factoring gives \(5(t-5)(t-15) = 0\). Our answers are \(t=5\) and \(t=15\), and since both of these values of \(t\) lie between \(0\) and \(20\), we keep both solutions. For \(t>20\), \(h(t) = 0\), and in this case, there are no solutions to \(0=375\). In terms of the model rocket, solving \(h(t) = 375\) corresponds to finding when, if ever, the rocket reaches \(375\) feet above the ground. Our two answers, \(t=5\) and \(t=15\) correspond to the rocket reaching this altitude twice - once \(5\) seconds after launch, and again \(15\) seconds after launch.

Graphing Piecewise Functions

Previously, we learned how to evaluate piecewise defined functions. Next, let's focus on how to graph them.

Given a piecewise function, sketch a graph.

  1. Indicate on the x-axis the boundaries defined by the intervals on each piece of the domain.
  2. For each piece of the domain, graph on that interval using the corresponding equation pertaining to that piece. Do not graph two functions over one interval because it would violate the criteria of a function.

Note: It is important to not just plot some points when graphing piecewise functions.

Example \(\PageIndex\): Graphing a Piecewise-Defined Function

Sketch a graph of the following piecewise-defined function:

Solution

Graph the linear function \(y=x+3\) on the interval \((−∞,1)\) and graph the quadratic function \(y=(x−2)^2\) on the interval \([1,∞)\). Since the value of the function at \(x=1\) is given by the formula \(f(x)=(x−2)^2\), we see that \(f(1)=1\). To indicate this on the graph, we draw a closed circle at the point \((1,1)\). The value of the function is given by \(f(x)=x+3\) for all \(x

An image of a graph. The x axis runs from -<a href=7 to 5 and the y axis runs from -4 to 6. The graph is of a function that has two pieces. The first piece is an increasing line that ends at the open circle point (1, 4) and has the label “f(x) = x + 3, for x < 1”. The second piece is parabolic and begins at the closed circle point (1, 1). After the point (1, 1), the piece begins to decrease until the point (2, 0) then begins to increase. This piece has the label “f(x) = (x - 2) squared, for x >

= 1”.The function has x intercepts at (-3, 0) and (2, 0) and a y intercept at (0, 3)." />

2) Sketch a graph of the function

An image of a graph. The x axis runs from -6 to 5 and the y axis runs from -2 to 7. The graph is of a function that has two pieces. The first piece is a decreasing line that ends at the closed circle point (2, 0) and has the label “f(x) = 2 - x, for x <= 2. The second piece is an increasing line and begins at the open circle point (2, 4) and has the label “f(x) = x + 2, for x ></p>
<p> 2.The function has an x intercept at (2, 0) and a y intercept at (0, 2).

Example \(\PageIndex\): Parking Fees Described by a Piecewise-Defined Function

In a big city, drivers are charged variable rates for parking in a parking garage. They are charged $10 for the first hour or any part of the first hour and an additional $2 for each hour or part thereof up to a maximum of $30 for the day. The parking garage is open from 6 a.m. to 12 midnight.

  1. Write a piecewise-defined function that describes the cost \(C\) to park in the parking garage as a function of hours parked \(x\).
  2. Sketch a graph of this function \(C(x).\)

Solution

1.Since the parking garage is open 18 hours each day, the domain for this function is \(\\). The cost to park a car at this parking garage can be described piecewise by the function

2.The graph of the function consists of several horizontal line segments.

An image of a graph. The x axis runs from 0 to 18 and is labeled “x, hours”. The y axis runs from 0 to 32 and is labeled “y, cost in dollars”. The function consists 11 pieces, all horizontal line segments that begin with an open circle and end with a closed circle. The first piece starts at x = 0 and ends at x = 1 and is at y = 10. The second piece starts at x = 1 and ends at x = 2 and is at y = 12. The third piece starts at x = 2 and ends at x = 3 and is at y = 14. The fourth piece starts at x = 3 and ends at x = 4 and is at y = 16. The fifth piece starts at x = 4 and ends at x = 5 and is at y = 18. The sixth piece starts at x = 5 and ends at x = 6 and is at y = 20. The seventh piece starts at x = 6 and ends at x = 7 and is at y = 22. The eighth piece starts at x = 7 and ends at x = 8 and is at y = 24. The ninth piece starts at x = 8 and ends at x = 9 and is at y = 26. The tenth piece starts at x = 9 and ends at x = 10 and is at y = 28. The eleventh piece starts at x = 10 and ends at x = 18 and is at y = 30.

Exercise \(\PageIndex\)

The cost of mailing a letter is a function of the weight of the letter. Suppose the cost of mailing a letter is \(49¢\) for the first ounce and \(21¢\) for each additional ounce. Write a piecewise-defined function describing the cost \(C\) as a function of the weight \(x\) for \(0

Hint

The piecewise-defined function is constant on the intervals \((0,1],\,(1,2],\,….\)

Answer

Example \(\PageIndex\)

Sketch a graph of the function.

Solution

Each of the component functions is from our library of toolkit functions, so we know their shapes. We can imagine graphing each function and then limiting the graph to the piece we need for the indicated domain of the piecewise function we are graphing. At the endpoints of the domain interval, draw open circles to indicate where the endpoint is not included because of a less-than or greater-than inequality; we draw a closed circle where the endpoint is included because of a less-than-or-equal-to or greater-than-or-equal-to inequality.

Figure \(\PageIndex\) shows the three components of the piecewise function graphed on separate coordinate systems.

[Graph of each part of the piece-wise function f(x)]


Figure \(\PageIndex\): Graph of each part of the piece-wise function f(x)

Now that we have sketched each piece individually, we then combine them in the same coordinate plane to form the graph of the piecewise function. See Figure \(\PageIndex\).

[Graph of the entire function.]

Analysis

Note that the graph does pass the vertical line test even at \(x=1\) and \(x=2\) because the points \((1,3)\) and \((2,2)\) are not part of the graph of the function, though \((1,1)\) and \((2, 3)\) are.

You Try \(\PageIndex\)

Graph the following piecewise function.

[Graph of f(x).]

Answer

This page titled Page 2.7: Piecewise Defined Functions is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Chau D Tran via source content that was edited to the style and standards of the LibreTexts platform.

  1. Back to top

Recommended articles

  1. Article type Section or Page Author Chau D Tran License CC BY License Version 4.0 Show Page TOC yes
  2. Tags
    1. algebraic function
    2. cubic function
    3. degree
    4. linear function
    5. Logarithmic Function
    6. mathematical model
    7. piecewise-defined function
    8. point-slope equation
    9. polynomial function
    10. power function
    11. quadratic function
    12. rational function
    13. root function
    14. slope
    15. slope-intercept form
    16. source@https://openstax.org/details/books/calculus-volume-1
    17. source[1]-math-123857
    18. source[1]-math-129952
    19. source[1]-math-2477
    20. source[1]-math-43618
    21. transcendental function
    22. transformation of a function