Piecewise Functions

This section covers:

Introduction to Piecewise Functions



Piecewise 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); they are defined differently for different intervals of \(x\). So \(y\) is defined differently for different values of \(x\); we use the \(x\) to look up what interval it’s in, so we can find out what the \(y\) is supposed to be.

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:

Piecewise Function


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



Domain:  \(\mathbb{R},\,\,\,\text{or}\,\,\left( {-\infty ,\infty } \right)\)

Range:  \(\mathbb{R},\,\,\,\text{or}\,\,\left( {-\infty ,\infty } \right)\)


So 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{ }\,&\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. So \(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.) So \(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.

Piecewise Function Graph

\(\displaystyle f\left( x \right)=\left\{ \begin{array}{l}-2x+8\,\,\,\,\,\,\text{if }x\le 4\\\frac{1}{2}x-2\,\,\,\,\,\,\,\,\,\text{if }x>4\end{array} \right.\)





       Domain: \(\mathbb{R},\,\,\,\text{or}\,\,\left( {-\infty ,\infty } \right)\)

       Range: \(\left( {0,\infty } \right)\)


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





       Domain:  \(\mathbb{R},\,\,\,\text{or}\,\,\left( {-\infty ,\infty } \right)\)

       Range:  \(\mathbb{R},\,\,\,\text{or}\,\,\left( {-\infty ,\infty } \right)\)


We can actually put piecewise functions in the graphing calculator:

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!)

Let’s try this for the functions we used above:

Piecewise Function Check Boundary Points
 \(\displaystyle f\left( x \right)=\left\{ \begin{array}{l}-2x+8\,\,\,\,\,\,\,\text{if }x\le 4\\\frac{1}{2}x-2\,\,\,\,\,\,\,\,\,\,\text{if }x>4\end{array} \right.\) Let’s check \(x=4\) in both parts of the function, since 4 is the “boundary point”:



Since \(0=0\), this piecewise function is continuous.

\(\displaystyle f\left( x \right)=\left\{ \begin{array}{l}x+4\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }x<1\\2\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if 1 }\le x<4\\-5+x\,\,\,\,\,\,\,\,\,\text{if }x\ge 4\end{array} \right.\) Let’s check in the first two parts of the function. Note in the second part, \(y\) is always 2:



Since \(5\ne 2\), we can stop here, and note that this piecewise function is non-continuous. If the \(y\)’s were equal, we’d have to go one to check the next boundary point at \(x=4\).


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:

Deriving Piecewise Function Equations from Graphs


Absolute Value as a Piecewise Function

We can write absolute value functions as piecewise functions – it’s really cool!  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|\text{ }=\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 might want to review Quadratic Inequalities for the second example below):

Absolute Value Function Method to get Piecewise Function
\(g\left( x \right)=\left| {2x+3} \right|\) Let’s first find the “boundary line”. We do this by setting what’s inside the absolute value to 0, and then solving for \(\boldsymbol{x}\).

When \(2x+3\ge 0\), we get \(\displaystyle x\ge -\frac{3}{2}\) (actually, we can keep the \(\ge \) when we solve). When \(2x+3\) is positive, we just take it “as is”, but if it’s negative, we have to negate the whole thing.

Therefore, the piecewise function is:

\(\displaystyle \left| {2x+3} \right|=\left\{ \begin{array}{l}2x+3,\,\,\,\,\,\,\,\,\,\text{if }x\ge -\frac{3}{2}\text{ }\\-2x-3,\,\,\,\,\,\text{if }x<-\frac{3}{2}\end{array} \right.\)

Try it – it works!

\(f\left( x \right)=\left| {{{x}^{2}}-4} \right|\) Let’s first find the “boundary line(s)”; we set what’s inside the absolute value to 0.


When \({{x}^{2}}-4\ge 0\), we get \(x\le -2\) or \(x\ge 2\) (try some numbers!). When \({{x}^{2}}-4\) is positive, we just take it “as is”, but if it’s negative, we have to negate it.

The piecewise function is:

\(\displaystyle \left| {{{x}^{2}}-4} \right|=\left\{ \begin{array}{l}{{x}^{2}}-4,\,\,\,\,\,\text{if }x\le -2\\4-{{x}^{2}}\text{,}\,\,\,\,\,\,\text{if }-2<x<2\\{{x}^{2}}-4,\,\,\,\,\,\text{if }x\ge 2\text{ }\end{array} \right.\)     or     \(\displaystyle \left| {{{x}^{2}}-4} \right|=\left\{ \begin{array}{l}{{x}^{2}}-4,\,\,\,\,\,\,\text{if }x\le -2\text{ }\,\,\text{or}\,\,\text{ }x\ge 2\\4-{{x}^{2}}\text{,}\,\,\,\,\,\,\,\text{if }-2<x<2\end{array} \right.\)

Again (since the function is continuous), it really doesn’t matter where we have the \(\le \) and \(\ge \) (as opposed to \(<\) and \(>\)), as long as we don’t repeat them.

\(f\left( x \right)=2x+\left| {x+2} \right|\) This one’s a little trickier, since we have an \(x\) inside and outside the absolute value. For the “boundary line”, we only use what is inside the absolute value.

When \(x+2\ge 0\), we get \(x\ge -2\). But for the piecewise function, we have to use the whole function, including the part that’s outside the absolute value. So, the piecewise function is:

\(\displaystyle 2x+\left| {x+2} \right|=\left\{ \begin{array}{l}2x+x+2,\,\,\,\,\,\text{if }x\ge -2\\2x-x-2,\,\,\,\,\,\text{if }x<-2\end{array} \right.\)

 Let’s simplify:

\(\displaystyle 2x+\left| {x+2} \right|=\left\{ \begin{array}{l}3x+2,\,\,\,\,\,\,\,\text{if }x\ge -2\\x-2,\,\,\,\,\,\,\,\,\,\,\text{if }x<-2\end{array} \right.\)

Try some values less than and great then –2; they should work!

\(g\left( x \right)=\left| {{{x}^{2}}-4x-5} \right|\) This one is best solved with a sign chart since we have a quadratic and we need to know where the function is positive and negative.

First, factor the quadratic inside the absolute value function to \(\left( {x-5} \right)\left( {x+1} \right)\). Then use a sign chart to see where the factors are positive and negative, and remember that where the factors are positive, we use the function “as is”, and where the factors are negative, we negate the function:

\(\displaystyle \left| {{{x}^{2}}-4x-5} \right|=\left\{ \begin{array}{l}{{x}^{2}}-4x-5,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\text{if }x\le -1\,\,\,\,\text{or}\,\,\,\,x\ge 5\\-\left( {{{x}^{2}}-4x-5} \right)\text{,}\,\,\,\,\text{if }-1<x<5\text{ }\end{array} \right.\)          

\(\displaystyle g\left( x \right)=\frac{{\left| {x+2} \right|}}{{x+2}}\) This is a rational function, since there’s a variable in the denominator.

When \(x+2\ge 0\), we get \(\displaystyle x\ge -2\). When \(x+2\) is positive, we just take it “as is”, but if it’s negative, we have to negate what’s in the absolute value: \(\displaystyle \frac{{\left| {x+2} \right|}}{{x+2}}=\left\{ \begin{array}{l}\frac{{x+2}}{{x+2}},\,\,\,\,\,\,\,\,\,\text{if }x\ge -2\\\frac{{-x-2}}{{x+2}},\,\,\,\,\,\,\text{if }x<-2\end{array} \right.\). But we have to be careful, since \(x\ne 2\) (domain restriction: the denominator would be 0).

Therefore, the piecewise function is: \(\displaystyle \frac{{\left| {x+2} \right|}}{{x+2}}=\left\{ \begin{array}{l}1,\,\,\,\,\,\,\,\,\,\,\text{if }x>-2\\-1,\,\,\,\,\,\,\text{if }x<-2\end{array} \right.\).

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

Obtaining Piecewise Functions from Graphs

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 we will 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.\)

Let’s make sure we 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\). So 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 3 “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:

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


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

Transformed Piecewise Function Graphs

Piecewise Function Word Problems

image224 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 cute dog weighs 60 pounds?


(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?).

So 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: Graph of Dog Word Problem 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. Whoa!  That costs more than a human haircut (at least my haircuts)!


You plan to sell She Love Math 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.


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. So 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. So we’ll pay \(10(75)+7.50(75)+5(x-150)\) for \(x\) shirts. Put in numbers and try it!

So the whole piecewise function is:

\(\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.\)           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.\)


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.\)


For the piecewise function to be continuous, at the boundary point (where the function changes), the two \(y\) values must be the same. So 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 an . 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!