Skip to main content
Mathematics LibreTexts

5.2: Piecewise Functions

  • Page ID
    178849
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    While continuity is pretty boring for most of the functions we have discussed thus far, there is one family of functions which can lead to any of the four different types of discontinuities.

    Piecewise functions are created by taking different pieces of functions on different parts of the domain. They are typically written like something below:

    \(f(x)=\left\{ \begin{array} {ll} A(x) & x>c \\ B(x) & x\le c \end{array} \right. \) \(g(x)=\left\{ \begin{array} {ll} z(x) & x\ne d \\ 0 & x=d \end{array} \right.\) \(h(x)=\left\{ \begin{array} {ll} p(x) & x\le \alpha \\ q(x) & \alpha <x\le \beta \\ r(x) & x>\beta \end{array} \right. \)

    (Each line inside tells the rule to follow first, and the values of \(x\) that follow that rule second.)

    We can use our limit taking skills for the individual pieces in order to graph a piecewise function.

    Example \(\PageIndex{1}\)

    Sketch \(f(x)=\left\{ \begin{array} {ll} \textcolor{green}{1-x^2} & x>1 \\ \textcolor{orange}{3} & x=1 \\ \textcolor{blue}{2x} & x<1 \end{array} \right.\)

    Solution

    We start by graphing the individual functions inside of our piecewise

    clipboard_eff4843621688a4e9d2938c83d151de4b.png

    Then plot the parts of them that are used together on on graph:

    clipboard_e80c364772e99a1a297bb340eec221456.png

    Notice the graph above has a jump discontinuity at \(x=1\) since:
    \(\textcolor{blue}{\displaystyle{\lim_{x\to 1^-}f(x)=\lim_{x\to 1^-}2x=2}}\) and \(\textcolor{green}{\displaystyle{\lim_{x\to 1^+}f(x)=\lim_{x\to 1^+}1-x^2=0}}\)

    To determine where a piecewise function is continuous, we check each of the pieces separately on their given intervals, and then we check the points where the functions (should) meet:

    Example \(\PageIndex{2}\)

    Find all discontinuities for \(f(x)=\left\{ \begin{array} {ll} \sin(x) & x<0 \\ 3x & 0<x\le 2 \\ \displaystyle{\frac{x-2}{x^2-4}} & x>2 \end{array} \right. \)

    Solution

    For \(a>2\): \(\displaystyle{\lim_{x\to a} f(x)=\lim_{x\to a} \frac{x-2}{x^2-4}=\frac{a-2}{a^2-4}=f(a)}\)
    So \(f(x)\) is continuous for \(x>2 \)

    For \(0<a<2\): \(\displaystyle{ \lim_{x\to a} f(x) = \lim_{x\to a} 3x = 3a=f(a)}\)
    So \(f(x)\) is continuous for \(0<x<2 \)

    For \(a<0\): \(\displaystyle{ \lim_{x\to a} f(x)=\lim_{x\to a} \sin(x)=\sin(a)=f(a)}\)
    So \(f(x)\) is continuous for \(x<0\)

    Now we check the points where these pieces meet:

    \(\displaystyle{\lim_{x\to 2^+}f(x)=\lim_{x\to 2^+} \frac{x-2}{x^2-4}=\lim_{x\to 2^+} \frac{x-2}{(x-2)(x+2)}=\lim_{x\to 2^+} \frac{1}{x+2}=\frac{1}{4}}\)

    \(\displaystyle{\lim_{x\to 2^-}f(x)=\lim_{x\to 2^-} 3x=6 }\)

    Therefore \(f(x)\) has a jump discontinuity at \(x=2\)

    \(\displaystyle{\lim_{x\to 0^+}f(x)=\lim_{x\to 0^+} 3x=0}\)

    \(\displaystyle{\lim_{x\to 0^-}f(x)=\lim_{x\to 0^-} \sin(x)=0 }\)

    But \(f(0)\) is not defined, so it does not match this limit.

    Therefore \(f(x)\) has a removable discontinuity at \(x=0\)

    Here is the graph of the function above, which confirms our answers.

    clipboard_e172cecb9b684a4bad830cc12dca4ba64.png

    We can also solve for constants in piecewise functions to ensure continuity:

    Example \(\PageIndex{3}\)

    For what \(\alpha\) is \(f(x)=\left\{ \begin{array} {ll} \displaystyle{\frac{x^2+4x-5}{x^2-1}} & x\ne 1 \\ \alpha & x=1 \end{array} \right.\) continuous at \(x=1\)?

    Solution

    To be continuous we want \(\displaystyle{ \lim_{x\to 1} f(x)=f(1)}\)

    We can see that \(f(1)=\alpha\), so we find the limit:

    \(\displaystyle{ \lim_{x\to 1}f(x)=\lim_{x\to 1} \frac{x^2+4x-5}{x^2-1} = \lim_{x\to 1} \frac{(x+5)(x-1)}{(x+1)(x-1)}= \lim_{x\to 1} \frac{x+5}{x+1}=3}\)

    Thus, we need \(\alpha=3\)

    This can even be done with more unknowns. (You'll just need more equations)

    Example \(\PageIndex{4}\)

    For what \(c\) and \(d\) is \(g(x)=\left\{ \begin{array} {ll} x^2+cx-2 & x>3 \\ 5 & x=3 \\ x+d\cos(\pi x) & x<3 \end{array} \right.\) continuous at \(x=3\)

    Solution

    To be continuous we want \(\displaystyle{ \lim_{x\to 3} g(x)=g(3)}\)

    We can see that \(g(3)=5\), so we find both sides of the limit:

    \(\displaystyle{ \lim_{x\to 3^+}g(x)=\lim_{x\to 3^+} x^2+cx-2 = 3^2+c\cdot 3-2 = 3c+7}\)

    Thus, we need \(3c+7=5\), which means \(\displaystyle{c=-\frac{2}{3}}\)

    \(\displaystyle{ \lim_{x\to 3^-}g(x)=\lim_{x\to 3^-} x+d\cos(\pi x) = 3+d\cos(3\pi) = 3-d}\)

    Thus, we need \(3-d=5\), which means \(d=-2\)

    So \(g(x)\) is continuous at \(x=3\) when \(\displaystyle{c=-\frac{2}{3}}\) and \(d=-2\)



    As we get more unknowns to solve for, we may end up with equations that involve more than one variable at a time. These are called systems of equations.

    There are a few different methods for solving a system of equations, but we will focus on just two: substitution and elimination

    Example \(\PageIndex{5}\)

    Find all solutions to the system of equations \(\left\{ \begin{array} {l} a+b=5 \\ 2a-b=7 \end{array} \right.\)

    Substitution Solution

    First, we solve for one letter in terms of the other in any equation:

    \( a+b=5 \rightarrow b=5-a\)

    Then we substitute it into the other equation:

    \(2a-(5-a)=7\)

    \(3a-5=7\)

    \(3a=12\)

    \(a=4\)

    Now we use \(b=5-a\) to get \(b=1\), and our solution must be \(a=4, b=1\)

    Elimination Solution

    Add both equations together:

    \( (a+b=5) + (2a-b=7) = (3a=12) \)

    \(3a=12 \rightarrow a=4\)

    Then plug in \(a=4\) into either equation to solve for \(b=1\), so our solution is again \(a=4, b=1\)

    Example \(\PageIndex{6}\)

    Find all solutions to the system of equations \(\left\{ \begin{array} {l} 2u+3v=1 \\ u=v+3 \end{array} \right.\)

    Substitution Solution

    This time we start off with one letter in terms of the other: \( u=v+3\)

    Then we substitute it into the other equation:

    \(2(v+3)+3v=1\)

    \(5v+6=1\)

    \(5v=-5\)

    \(v=-1\)

    Now we use \(u=v+3\) to get \(u=2\), and our solution must be \(u=2, v=-1\)

    Elimination Solution

    Subtract twice the bot equation from the top:

    \( (2u+3v=1) - 2(u=v+3) = (3v=-2v-5) \)

    \(3v=-2v-5 \rightarrow v=-1\)

    Then plug in \(v=-1\) into either equation to solve for \(u=2\), so our solution is again \(u=2, v=-1\)



    Lets try to use this in another continuity example:

    Example \(\PageIndex{7}\)

    For what \(m\) and \(b\) is \(f(x)=\left\{ \begin{array} {ll} x^2 & x\ge 2 \\ mx+b & 1\le x<2 \\ \displaystyle{\frac{x-1}{x^2-3x+2}} & x< 1\end{array} \right.\) continuous?

    Solution

    To be continuous we want \( \textcolor{red}{\displaystyle{ \lim_{x\to 1} f(x)=f(1)}}\) and \(\textcolor{green}{\displaystyle{ \lim_{x\to 2} f(x)=f(2)}}\)

    First we check both sides at \(\textcolor{red}{x=1}\):

    \(\displaystyle{ \lim_{x\to 1^+}f(x)=\lim_{x\to 1^+} mx+b = m\cdot 1 +b=m+b}\)

    \(\displaystyle{ \lim_{x\to 1^-}f(x)=\lim_{x\to 1^-} \frac{x-1}{x^2-3x+2} = \lim_{x\to 1^-} \frac{x-1}{(x-2)(x-1)}= \lim_{x\to 1^-} \frac{1}{x-2}=-1}\)

    \(f(1)=m\cdot 1+b=m+b\)

    We need all three of these to match, so \(m+b=-1\)

    Now we check both sides at \(\textcolor{green}{x=2}\):

    \(\displaystyle{ \lim_{x\to 2^+}f(x)=\lim_{x\to 2^+} x^2 = 2^2=4}\)

    \(\displaystyle{ \lim_{x\to 2^-}f(x)=\lim_{x\to 2^-} mx+b = m\cdot 2+b= 2m+b}\)

    \(f(2)=2^2=4\)

    We need all three of these to match, so \(2m+b=4\)

    Now we solve the system of equations \(\left\{ \begin{array} {l} \textcolor{red}{m+b=1} \\ \textcolor{green}{2m+b=4} \end{array} \right. \)

    \( (\textcolor{green}{2m+b=4})-( \textcolor{red}{m+b=1})=(m=3) \)

    Plugging this into either equation gives \(b=-2\)

    Therefore we need \(m=3\) and \(b=-2\) to make \(f(x)\) continuous everywhere



    This page titled 5.2: Piecewise Functions is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Kenn Huber.

    • Was this article helpful?