2.1: Function Compilations - Piecewise, Combinations, and Composition
Piecewise-Defined Functions
A person drinks a cup of coffee containing 300 mg of caffeine. The amount of caffeine in the body from the coffee decreases rapidly at first, then more slowly over time. Draw a graph representing this relationship between the amount of caffeine, C, in mg and the time, t, in seconds since it was ingested.
Solution
In this example, we were given a description of the relationship with words. We were able to build an approximate graph to represent this relationship. However, without more more information we could not build a formula or a table.
A piecewise function is a function whose definition changes depending on the value of its argument. The function is defined by different formulas for different parts of its domain.
For example, we can write the absolute value function \(f(x) = |x|\) as a piecewise function:
\(f ( x ) = | x | = \left\{ \begin{array} { c l } { x } & { \text { if } x \geq 0 } \\ { - x } & { \text { if } x < 0 } \end{array} \right.\)
In this case, the definition used depends on the sign of the \(x\)-value. If the \(x\)-value is positive, \(x ≥ 0\), then the function is defined by \(f(x) = x\). And if the \(x\)-value is negative, \(x < 0\), then the function is defined by \(f(x) = −x\). The graphs of these two pieces are shown below.
The graph of the absolute function itself is the combination of these two pieces on the same rectangular coordinate plane. The resulting graph is illustrated below.
How to: Given a piecewise function sketch a graph .
- Indicate on the \(x\)-axis the boundaries defined by the intervals on each piece of the domain. Each equation defines a graph for a column of the Cartesian coordinate plane.
- For each piece of the domain, graph on that interval using the corresponding equation pertaining to that piece. Do not graph two functions in the same interval because the graph would no longer be a graph of a function because it would fail the Vertical Line Test.
Example \(\PageIndex{1}\): Graph a 2-piece function
Graph: \(g ( x ) = \left\{ \begin{array} { c c c } { x ^ { 2 } } & { \text { if } } & { x < 0 } \\ { \sqrt { x } } & { \text { if } } & { x \geq 0 } \end{array} \right.\).
Solution
In this case, we graph the squaring function over negative \(x\)-values and the square root function over positive \(x\)-values.
Notice the open dot used at the origin for the squaring function and the closed dot used for the square root function. This was determined by the inequality that defines the domain of each piece of the function. The entire function consists of each piece graphed on the same coordinate plane.
Answer :
Example \(\PageIndex{2}\)
Sketch a graph of the following piecewise-defined function:
\[f(x)=\begin{cases}x+3, &x<1\\(x−2)^2, &x≥1\end{cases} \nonumber\]
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+2\) for all \(x<1\), but not at \(x=1\). To indicate this on the graph, we draw an open circle at \((1,4)\).
The figure at the right illustrates this piecewise-defined function that is linear for \(x<1\) and quadratic for \(x≥1.\)
Try It \(\PageIndex{3}\)
Graph the following piecewise functions.
| a. \(f(x)=\begin{cases}2−x, x≤2\\x+2, x>2\end{cases}.\) | b. \(f ( x ) = \left\{ \begin{array} { l l } { \frac { 2 } { 3 } x + 1 } & { \text { if } x < 0 } \\ { x ^ { 2 } } & { \text { if } x \geq 0 } \end{array} \right.\). |
- Answer
-
a.
b.
Example \(\PageIndex{4}\): Graph a 3-piece function
Sketch a graph of the function.
\[f(x)= \begin{cases} x^2 & \text{if $x \leq 1$} \\ 3 &\text{if $1<x\leq2$} \\ x &\text{if $x>2$} \end{cases} \nonumber \]
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 indicated domain. At the endpoints of the domain, we 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{4}\) shows the three components of the piecewise function graphed on separate coordinate systems.
Figure \(\PageIndex{4}\):
Graph of each part of the piece-wise function f(x)
(a)\( f(x)=x^2\) if \(x≤1\); (b) \(f(x)=3\) if \(1< x≤2\); (c) \(f(x)=x\) if \(x>2\)
|
Now that we have sketched each piece individually, we combine them in the same coordinate plane. See Figure \(\PageIndex{4s}\). 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. |
Example \(\PageIndex{5}\):
Graph: \(f ( x ) = \left\{ \begin{array} { l l } { x ^ { 3 } } & { \text { if } x < 0 } \\ { x } & { \text { if } 0 \leq x \leq 4 } \\ { 6 } & { \text { if } x > 4 } \end{array} \right.\).
Solution
In this case, graph the cubing function over the interval \((−∞,0)\). Graph the identity function over the interval \([0,4]\). Finally, graph the constant function \(f(x)=6\) over the interval \((4,∞)\). And because \(f(x)=6\) where \(x>4\), we use an open dot at the point \((4,6)\). Where \(x=4\), we use \(f(x)=x\) and thus \((4,4)\) is a point on the graph as indicated by a closed dot.
Answer :
Try It \(\PageIndex{6}\)
Graph the following piecewise function.
\[f(x)= \begin{cases} x^3 & \text{if $x < -1$} \\ -2 &\text{if $-1<x<4$} \\ \sqrt{x} &\text{if $x>4$} \end{cases} \nonumber \]
- Answer
Can more than one formula from a piecewise function be applied to a value in the domain?
No. Each value corresponds to one equation in a piecewise formula.
Evaluating Piecewise Functions
When evaluating piecewise functions, the value in the domain determines the appropriate definition to use.
Example \(\PageIndex{7}\):
Given the function \(h\), find \(h(−5), h(0),\) and \(h(3)\).
\[h(t)= \begin{cases}
7t+5 & \text{if $t<0$} \\
-16t^2+32t &\text{if $t\geq 0$}
\end{cases} \nonumber \]
Solution
Use \(h(t) = 7t + 3\) where \(t\) is negative, as indicated by \(t < 0\).
\(\begin{aligned} h ( t ) & = 7 t + 5 \\ h ( \color{Cerulean}{- 5}\color{Black}{ )} & = 7 ( \color{Cerulean}{- 5}\color{Black}{)} + 5 \\ & = - 35 + 5 \\ & = - 30 \end{aligned}\)
Where \(t\) is greater than or equal to zero, use \(h(t) = −16t^{2} + 32t\).
\( \begin{array} {rlrl}
h ( \color{Cerulean}{0}\color{Black}{ )}
& = - 16 ( \color{Cerulean}{0}\color{Black}{ )} + 32 ( \color{Cerulean}{0}\color{Black}{ )}
& \qquad h ( \color{Cerulean}{3}\color{Black}{ )}
& = 16 ( \color{Cerulean}{3}\color{Black}{ )} ^ { 2 } + 32 ( \color{Cerulean}{3}\color{Black}{ )}
\\
& =0 + 0
&& = -144 +96
\\
& =0
&& =-48
\end{array} \)
Answer :
\(h(−5) = −30, h(0) = 0,\) and \(h(3) = −48\)
Example \(\PageIndex{8}\): Working with a Piecewise Function
A cell phone company uses the function below to determine the cost, \(C\), in dollars for \(g\) gigabytes of data transfer.
\[C(g)= \begin{cases} 25 & \text{if $0<g<2$} \\ 25+10(g-2) &\text{if $g\geq2$} \end{cases} \nonumber \]
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 part of the domain our input falls in. Because 1.5 is less than 2, we use the first formula.
\[C(1.5)=$25 \nonumber \]
To find the cost of using 4 gigabytes of data, C(4), we see that our input of 4 is greater than 2, so we use the second formula.
\[C(4)=25+10(4−2)=$45 \nonumber \]
Analysis
The function is represented in Figure \(\PageIndex{8}\). We can see where the function changes from a constant to a shifted and stretched identity at \(g=2\). We plot the graphs for the different formulas on a common set of axes, making sure each formula is applied on its proper domain.
The greatest Integer Function
The greatest integer function , denoted \(f(x) = {[{[ x ]}]} \) assigns the greatest integer less than or equal to any real number in its domain. For example,
\(\begin{aligned} f ( 2.7 ) & = {[{[ 2.7 ]}]} &= 2 \\ f ( \pi ) & = {[{[ \pi ]}]} &= 3 \\ f ( 0.23 ) & = {[{[0.23 ]}]} &= 0 \\ f ( - 3.5 ) & = {[{[ -3.5 ]}]} &= - 4 \end{aligned}\)
This function associates any real number with the greatest integer less than or equal to it and should not be confused with rounding off.
Example \(\PageIndex{9}\): Greatest Integer Function
Graph: \(f(x) = {[{[ x ]}]} \).
Solution
If \(x\) is any real number, then \(y = \) is the greatest integer less than or equal to \(x\).
\(\begin{aligned} \vdots\\- 1 \leq x < 0 & \color{Cerulean}{\Rightarrow}\color{Black}{ y} = {[{[ x ]}]}= -1 \\ 0 \leq x < 1 & \color{Cerulean}{\Rightarrow} \color{Black}{y} = {[{[ x ]}]}= 0 \\ 1 \leq x < 2 & \color{Cerulean}{\Rightarrow}\color{Black}{ y} = {[{[ x ]}]} = 1 \\ & \vdots \end{aligned}\)
Using this, we obtain the following graph.
Answer :
The domain of the greatest integer function consists of all real number \(\mathbb{R}\) and the range consists of the set of integers \(\mathbb{Z}\). This function is often called the floor function and has many applications in computer science.
Writing Piecewise-Defined Functions
How to: Given a piecewise function, write the formula and identify the domain for each interval.
- Identify the intervals for which different rules apply.
- Determine formulas that describe how to calculate an output from an input in each interval.
- Use braces and if-statements to write the function.
Example \(\PageIndex{10}\): Writing a Piecewise Function
A museum charges $5 per person for a guided tour with a group of 1 to 9 people or a fixed $50 fee for a group of 10 or more people. Write a function relating the number of people, \(n\), to the cost, \(C\).
Solution
Two different formulas will be needed. For \(n\)-values under 10, \(C=5n\). For values of n that are 10 or greater, \(C=50\).
\[C(n)= \begin{cases} 5n & \text{if $n < 10$} \\ 50 &\text{if $n\geq10$} \end{cases} \nonumber \]
Analysis
The function is represented in Figure \(\PageIndex{10}\). The graph is a diagonal line from \(n=0\) to \(n=10\) and a constant after that. In this example, the two formulas agree at the meeting point where \(n=10\), but not all piecewise functions have this property.
Example \(\PageIndex{11}\): Writing a Greatest Integer 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.
- Write a piecewise-defined function that describes the cost \(C\) to park in the parking garage as a function of hours parked \(x\).
- 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 \( \{ x \;|\; 0 < x ≤ 18 \} \). The cost to park a car at this parking garage can be described piecewise by the function
\[C(x)=\begin{cases}
10, & 0 < x ≤ 1 \\
12, & 1<x≤2\\
14, & 2<x≤3\\
16, & 3<x≤4\\
⋮\\
30, & 10<x≤18\end{cases}. \nonumber \]
2.The graph of the function consists of several horizontal line segments.
Try It \(\PageIndex{12}\)
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<x≤3\), where \(C\) is measured in cents and \(x\) is measured in ounces.
- Hint
-
The piecewise-defined function is constant on the intervals (0,1], (1,2],….
- Answer
-
\[C(x)=\begin{cases}49, &0<x≤1\\70, &1<x≤2\\91, &2<x≤3\end{cases} \nonumber \]