Piecewise Functions

Introduction to Piecewise Functions

Piecewise functions (or piece-wise functions) are just what they are named: pieces of different functions (sub-functions) all on one graph. The easiest way to think of them is if you drew more than one function on a graph, and you just erased parts of the functions where they aren’t supposed to be (along the $ x$’s). Thus, the $ y$’s are defined differently, depending on the intervals where the $ x$’s are.

Note that there is an example of a piecewise function’s inverse here in the Inverses of Functions section.

Here’s an example and graph:


What this means is for every $ x$ less than or equal to –2, we need to graph the line $ 2x+8$, as if it were the only function on the graph. For every $ x$ value greater than –2, we need to graph $ {{x}^{2}}$, as if it were the only function on the graph. Then we have to “get rid of” the parts that we don’t need. Remember that we still use the origin as the reference point for both graphs!

See how the vertical line $ x=-2$ acts as a “boundary” line between the two graphs?

Note that the point $ (–2,4)$ has a closed circle on it. Technically, it should only belong to the $ 2x+8$ function, since that function has the less than or equal sign, but since the point is also on the $ {{x}^{2}}$ graph, we can just use a closed circle as if it appears on both functions. See, not so bad, right?

Evaluating Piecewise Functions

Sometimes, you’ll be given piecewise functions and asked to evaluate them; in other words, find the $ y$ values when you are given an $ x$ value. Let’s do this for $ x=-6$ and $ x=4$ (without using the graph). Here is the function again:

$ \displaystyle f\left( x \right)=\left\{ \begin{align}2x+8\,\,\,\,\,&\text{ if }x\le -2\\{{x}^{2}}\,\,\,\,\,\,\,\text{ }\,&\text{ if }x>-2\end{align} \right.$

We first want to look at the conditions at the right first, to see where our $ x$ is. When $ x=-6$, we know that it’s less than –2, so we plug in our $ x$ to $ 2x+8$ only. $ f(x)$ or $ y$ is $ (2)(-6)+8=-4$. We don’t even care about the $ \boldsymbol{{x}^{2}}$!  It’s that easy. You can also see that we did this correctly by using the graph above.

Now try $ x=4$. We look at the right first, and see that our $ x$ is greater than –2, so we plug it in the $ {{x}^{2}}$.  (We can just ignore the $ 2x+8$ this time.) $ f(x)$ or $ y$ is $ {{4}^{2}}=16$.

Graphing Piecewise Functions

You’ll probably be asked to graph piecewise functions. Sometimes the graphs will contain functions that are non-continuous or discontinuous, meaning that you have to pick up your pencil in the middle of the graph when you are drawing it (like a jump!). Continuous functions means that you never have to pick up your pencil if you were to draw them from left to right.

And remember that the graphs are true functions only if they pass the Vertical Line Test.

Let’s draw these piecewise functions and determine if they are continuous or non-continuous. Note how we draw each function as if it were the only one, and then “erase” the parts that aren’t needed. We’ll also get the Domain and Range like we did here in the Algebraic Functions section.


We can actually put piecewise functions in the graphing calculator:

How to Tell if Piecewise Function is Continuous or Non-Continuous

To tell if a piecewise graph is continuous or non-continuous, you can look at the boundary points and see if the $ y$ point is the same at each of them. (If the $ y$’s were different, there’d be a “jump” in the graph!)

Try this for the functions we used above:

Obtaining Equations from Piecewise Function Graphs

You may be asked to write a piecewise function, given a graph. Now that we know what piecewise functions are all about, it’s not that bad! To review how to obtain equations from linear graphs, see Obtaining the Equations of a Line, and from quadratics, see Finding a Quadratic Equation from Points or a Graph.

Here are the graphs, with explanations on how to derive their piecewise equations:

Absolute Value as a Piecewise Function

You may be asked to write an absolute value function as a piecewise function. You might want to review Solving Absolute Value Equations and Inequalities before continuing on to this topic.

Let’s say we have the function $ f\left( x \right)=\left| x \right|$. From what we learned earlier, we know that when $ x$ is positive, since we’re taking the absolute value, it will still just be $ x$. But when $ x$ is negative, when we take the absolute value, we have to take the opposite (negate it), since the absolute value has to be positive. Make sense? So, for example, if we had $ |5|$, we just take what’s inside the absolute sign, since it’s positive. But for $ |–5|$, we have to take the opposite (negative) of what’s inside the absolute value to make it $ \displaystyle 5\,\,(–5=5)$.

This means we can write this absolute value function as a piecewise function. Notice that we can get the “turning point” or “boundary point” by setting whatever is inside the absolute value to 0. Then we’ll either use the original function, or negate the function, depending on the sign of the function (without the absolute value) in that interval.

For example, we can write $ \displaystyle \left| x \right|=\left\{ \begin{array}{l}x\,\,\,\,\,\,\,\,\,\text{if }x\ge 0\\-x\,\,\,\,\,\text{if }x<0\end{array} \right.$. Also note that, if the function is continuous (there is no “jump”) at the boundary point, it doesn’t matter where we put the “less than or equal to” (or “greater than or equal to”) signs, as long as we don’t repeat them! We can’t repeat them because, theoretically, we can’t have two values of $ y$ for the same $ x$, or we wouldn’t have a function.

Here are more examples, with explanations. You can also check these in the graphing calculator using $ {{Y}_{1}}=$ and MATH NUM 1 (abs). (You might want to review Quadratic Inequalities for the second example below):


You may also be asked to take an absolute value graph and write it as a piecewise function:

Transformations of Piecewise Functions

Let’s do a transformation of a piecewise function. We learned how about Parent Functions and their Transformations here in the Parent Graphs and Transformations section. You’ll probably want to read this section first, before trying a piecewise transformation. Let’s transform the following piecewise function flipped around the $ x$-axis, vertically stretched by a factor of 2 units, 1 unit to the right, and 3 units up.

So, let’s draw $ -2f\left( x-1 \right)+3$, where:

$ \displaystyle f\left( x \right)=\left\{ \begin{align}x+4\,\,\,\,\,\,\,\,&\text{ if }x<1\\2\,\,\,\,\,\,\,\,&\text{ if 1 }\le x<4\\x-5\,\,\,\,\,\,\,\,&\text{ if }x\ge 4\end{align} \right.$

Make sure to use the “boundary” points when we fill in the t-chart for the transformation. Remember that the transformations inside the parentheses are done to the $ x$ (doing the opposite math), and outside are done to the $ y$. To come up with a t-chart, as shown in the table below, we can use key points, including two points on each of the “boundary lines”.

Note that because this transformation is complicated, we can come up with a new piecewise function by transforming the three “pieces” and also transforming the “$ x$”s where the boundary points are (adding 1, or going to the right 1), since we do the opposite math for the “$ x$”s. To get the new functions in each interval, we can just substitute “$ x-1$” for “$ x$” in the original equation, multiply by –2, and then add 3. For example, for the first part of the piecewise function, $ \displaystyle -2f\left( {x-1} \right)+3=-2\left[ {\left( {x-1} \right)+4} \right]+3=-2x-3$. So we have:

$ \displaystyle \begin{array}{l}-2f\left( {x-1} \right)+3=\\\,\left\{ \begin{array}{l}-2\left( {\left( {x-1} \right)+4} \right)+3=-2x-3,\,\,\,\,\text{ }\,\text{ }\,\text{if }x-1<1\,\,\left( {x<2} \right)\\-2\left( 2 \right)+3=-1,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{ }\,\text{ if }\,\text{ 2 }\le x<5\\-2\left( {\left( {x-1} \right)-5} \right)+3=-2x+15,\,\,\text{ }\text{ if }x\ge 5\end{array} \right.\end{array}$

Here are the “before” and “after” graphs, including the t-chart:

Piecewise Function Word Problems

Problem:

Your favorite dog groomer charges according to your dog’s weight. If your dog is 15 pounds and under, the groomer charges $35. If your dog is between 15 and 40 pounds, she charges $40. If your dog is over 40 pounds, she charges $40, plus an additional $2 for each pound.

(a)  Write a piecewise function that describes what your dog groomer charges.  (b) Graph the function.  (c) What would the groomer charge if your dog weighs 60 pounds?

Solution:

(a)  We see that the “boundary points” are 15 and 40, since these are the weights where prices change. Since we have two boundary points, we’ll have three equations in our piecewise function. We have to start at 0, since dogs have to weigh over 0 pounds:  $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }……\,\,\,\,\,\,\,\,\,\text{if }0<x\le 15\\\text{ }……\,\,\,\,\,\,\,\,\,\text{if }15<x\le 40\\\text{ }……\,\,\,\,\,\,\,\,\,\text{if }x>40\end{array} \right.$

We are looking for the “answers” (how much the grooming costs) to the “questions” (how much the dog weighs) for the three ranges of prices. The first two are just flat fees ($35 and $40, respectively). The last equation is a little trickier; the groomer charges $40 plus $2 for each pound over 40. Let’s try real numbers: if your dog weighs 60 pounds, she will charge $40 plus $2 times $ 20\,\,(60–40)$. We’ll turn this into an equation: $ 40+2(x–40)$, which simplifies to $ 2x–40$ (see how 2 is the slope?).

The whole piecewise function is:  $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }35\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }0<x\le 15\\\text{ }40\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }15<x\le 40\\\text{ }40+2\left( {x-40} \right)\,\,\,\,\,\,\,\,\text{if }x>40\end{array} \right.$             or        $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }35\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }0<x\le 15\\\text{ }40\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }15<x\le 40\\\text{ }2x-40\,\,\,\,\,\,\,\text{if }x>40\end{array} \right.$

(b)   Let’s graph:Note that this piecewise equation is non-continuous. Also note a reasonable domain for this problem might be $ \left( {0,200} \right]$ (given dogs don’t weigh over 200 pounds!) and a reasonable range might be $ \left[ {35} \right]\cup \left[ {40,360} \right]$.

(c)  If your dog weighs 60 pounds, we can either use the graph, or the function to see that you would have to pay $80.

Problem:

You plan to sell t-shirts as a fundraiser. The wholesale t-shirt company charges you $10 a shirt for the first 75 shirts. After the first 75 shirts you purchase up to 150 shirts, the company will lower its price to $7.50 per shirt. After you purchase 150 shirts, the price will decrease to $5 per shirt. Write a function that models this situation.

Solution:

We see that the “boundary points” are 75 and 150, since these are the number of t-shirts bought where prices change. Since we have two boundary points, we’ll have three equations in our piecewise function. We’ll start with $ x\ge 1$, since, we assume at least one shirt is bought. Note in this problem, the number of t-shirts bought ($ x$), or the domain, must be a integer, but this restriction shouldn’t affect the outcome of the problem.

$ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }……\text{ if }1\le x\le 75\\\text{ }……\text{ if }75<x\le 150\\\text{ }……\text{ if }x>150\end{array} \right.$

We are looking for the “answers” (total cost of t-shirts) to the “questions” (how many are bought) for the three ranges of prices.

For up to and including 75 shirts, the price is $10, so the total price would $ 10x$. For more than 75 shirts but up to 100 shirts, the cost is $7.50, but the first 75 t-shirts will still cost $10 per shirt. The second function includes the $750 spent on the first 75 shirts (75 times $10), and also includes $7.50 times the number of shirts over 75, which would be $ (x-75)$. For example, if you bought 80 shirts, you’d have to spend $ \$10\times 75=\$750$, plus $ \$7.50\times 5\,$ (80 – 75)  for the shirts after the 75th shirt.

Similarly, for over 150 shirts, we would still pay the $10 price up through 75 shirts, the $7.50 price for 76 to 150 shirts (75 more shirts), and then $5 per shirt for the number of shirts bought over 150. We’ll pay $ 10(75)+7.50(75)+5(x-150)$ for $ x$ shirts. Put in numbers and try it!

The whole piecewise function is:  $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }10x\text{ }\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }1\le x\le 75\\\text{ 10}\left( {75} \right)+7.5\left( {x-75} \right)\text{ }\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{ if 7}5<x\le 150\\\text{ 10}\left( {75} \right)+7.5\left( {75} \right)+5\left( {x-150} \right)\text{ }\,\text{if }x>150\end{array} \right.$          or           $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }10x\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }1\le x\le 75\\\text{ }7.5x\text{ }+\text{ }187.5\,\,\,\,\,\,\,\,\text{if 7}5<x\le 150\\\text{ }5x+562.5\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }x>150\end{array} \right.$

Problem:

A bus service costs $50 for the first 400 miles, and each additional 300 miles (or a fraction thereof) adds $10 to the fare. Use a piecewise function to represent the bus fare in terms of the distance in miles.

Solution:

This is actually a tricky problem, but let’s first think first about the “boundary point”, which is 400. It’s pretty straightforward when the ride is less than 400 miles; the cost is $50.

For greater than 400 miles, we have to subtract out the first 400 miles (but remember to include the first $50), divide the number of miles left by 300 miles (and round up, if there’s a fractional amount), and multiply that by $10.

The tricky part is when we “round up” for a portion of the next 300 miles. We can use a “ceiling” function (designated by $ \left\lceil {} \right\rceil $); this function gives the least integer that is greater than or equal to its input; for example, the ceiling of both 3.5 and 4  is 4.

Thus, this is what we have:  $ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}\text{ }50\text{ }\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }0\le x\le 400\\\text{ }50+\left( {10\times \left\lceil {\displaystyle \frac{{x-400}}{{300}}} \right\rceil } \right)\text{ }\,\,\,\,\,\text{ if }x>400\end{array} \right.$

Let’s try it! If we have a 1500-mile ride, the cost would be $ \displaystyle 50+\left( {10\times \left\lceil {\frac{{1500-400}}{{300}}} \right\rceil } \right)\text{ }=50+\left( {10\times 4} \right)=\$90$.

Problem:

What value of $ \boldsymbol{a}$ would make this piecewise function continuous?

$ \displaystyle f\left( x \right)=\left\{ \begin{array}{l}3{{x}^{2}}+4\,\,\,\,\,\text{ if }x<-2\\5x+\boldsymbol{a}\,\,\,\,\,\,\,\,\text{if }x\ge -2\end{array} \right.$

Solution:

For the piecewise function to be continuous, at the boundary point (where the function changes), the two $ y$ values must be the same. We can plug in –2 for $ x$ in both of the functions and make sure the $ y$’s are the same:  $ \begin{align}3{{x}^{2}}+4&=5x+a\\3{{\left( {-2} \right)}^{2}}+4&=5\left( {-2} \right)+a\\12+4&=-10+a\\a&=26\end{align}$

If $ a=26$, the piecewise function is continuous!

Learn these rules, and practice, practice, practice!


More Practice: Use the Mathway widget below to try write a Piecewise Function. Click on Submit (the blue arrow to the right of the problem) and click on Write the Absolute Value as Piecewise to see the answer.

You can also type in your own problem, or click on the three dots in the upper right hand corner and click on “Examples” to drill down by topic.

If you click on Tap to view steps, or Click Here, you can register at Mathway for a free trial, and then upgrade to a paid subscription at any time (to get any type of math problem solved!).

On to Matrices and Solving Systems with Matrices – you are ready!

Scroll to Top