Piecewise-Defined Functions
Sometimes, we come across a function that requires more than one formula in order to obtain the given output. For example, in the toolkit functions, we introduced the absolute value function [latex]f\left(x\right)=|x|[/latex]. With a domain of all real numbers and a range of values greater than or equal to 0, absolute value can be defined as the magnitude, or modulus, of a real number value regardless of sign. It is the distance from 0 on the number line. All of these definitions require the output to be greater than or equal to 0.
If we input 0, or a positive value, the output is the same as the input.
[latex]f\left(x\right)=x\text{ if }x\ge 0[/latex]
If we input a negative value, the output is the opposite of the input.
[latex]f\left(x\right)=-x\text{ if }x<0[/latex]
Because this requires two different processes or pieces, the absolute value function is an example of a piecewise function. A piecewise function is a function in which more than one formula is used to define the output over different pieces of the domain.
piecewise function
A piecewise function is a function in which more than one formula is used to define the output. Each formula has its own domain, and the domain of the function is the union of all these smaller domains. We notate this idea like this:
[latex]f\left(x\right)=\begin{cases}\text{formula 1 if x is in domain 1}\\ \text{formula 2 if x is in domain 2}\\ \text{formula 3 if x is in domain 3}\end{cases}[/latex]
In piecewise notation, the absolute value function is
[latex]|x|=\begin{cases}\begin{align}x&\text{ if }x\ge 0\\ -x&\text{ if }x<0\end{align}\end{cases}[/latex]
We use piecewise functions to describe situations in which a rule or relationship changes as the input value crosses certain “boundaries.”
- For example, consider a simple tax system in which incomes up to [latex]$10,000[/latex] are taxed at [latex]10\%[/latex], and any additional income is taxed at [latex]20\%[/latex]. The tax on a total income, [latex]S[/latex] , would be [latex]0.1S[/latex] if [latex]{S}\le$10,000[/latex] and [latex]1000 + 0.2 (S - $10,000)[/latex] , if [latex]S> $10,000[/latex] .
- 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.
- You can read it as a list of if-then statements for the function value.
Piecewise functions are challenging to understand. Give yourself time to work with them repeatedly on paper, evaluating and graphing different functions. It’s natural to need to work many problems before you feel comfortable with them.
[latex]C\left(g\right)=\begin{cases}\begin{align}{25} \hspace{2mm}&\text{ if }\hspace{2mm}{ 0 }<{ g }<{ 2 }\\ { 25+10 }\left(g - 2\right) \hspace{2mm}&\text{ if }\hspace{2mm}{ g}\ge{ 2 }\end{align}\end{cases}[/latex]
Find the cost of using [latex]1.5[/latex] gigabytes of data and the cost of using [latex]4[/latex] gigabytes of data.
- Indicate on the [latex]x[/latex]-axis the boundaries defined by the intervals on each piece of the domain.
- 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.
[latex]f\left(x\right)=\begin{cases}\begin{align}{ x }^{2} \hspace{2mm}&\text{ if }\hspace{2mm}{ x }\le{ 1 }\\ { 3 } \hspace{2mm}&\text{ if }\hspace{2mm} { 1 }<{ x }\le 2\\ { x } \hspace{2mm}&\text{ if }\hspace{2mm}{ x }>{ 2 }\end{align}\end{cases}[/latex]
You can view the transcript for “Piecewise Functions in Desmos” here (opens in new window).
Graph the following piecewise function with an online graphing calculator.
[latex]f\left(x\right)=\begin{cases}\begin{align}{ x}^{3} \hspace{2mm}&\text{ if }\hspace{2mm}{ x }<{-1 }\\ { -2 } \hspace{2mm}&\text{ if } \hspace{2mm}{ -1 }<{ x }<{ 4 }\\ \sqrt{x} \hspace{2mm}&\text{ if }\hspace{2mm}{ x }>{ 4 }\end{align}\end{cases}[/latex]