# What Are Piecewise-defined Functions? (Lots of Examples)

(D4M) — Here is the video transcript for this video.

00:00
in this episode you’ll learn what a piecewise defined function is and we’ll
practice evaluating them and then graphing them let’s do some math [Music]
okay we’re going to begin with what are piecewise defined functions
um and we’re going to do this through a series of examples example one here
so here is an example of a piecewise defined function
so first off it needs to be a function so we’re using function notation here
and we’re going to say it’s piecewise defined because on its domain which is
specified right here we can say how the different pieces are defined so
for example when x is less than zero then we will substitute x into this part
right here when a given x is a greater than or
equal to zero then we’ll substitute into this part right here

00:01
and so let’s see some examples let’s find f of minus one
so here’s how we’ll work this out f of minus one is equal to
so now um i’m substituting in minus one so now i’m going to check which
condition do i uh check over here so minus one is less than equal to one
that’s true and minus one is greater than or equal
to one that’s false so we’re gonna use the one that’s true
so we’re gonna use two times minus one and then plus one and so that’s minus
two plus one and so that’s minus one now what about zero here let’s
substitute in zero so f of zero here zero is less than one
that condition is true so i’m going to plug in 0 here so we’re going to get 2
times 0 plus 1 and then that’s just 0 plus 1 or just 1.
and then for this third example here this part c
now i’m going to substitute in 2 here so we’re going to substitute in 2
and now i check which condition is 2 true so 2 is greater than or equal to 1 so

00:02
i’m going to use this piece right here so 2 times 2 plus 2
and that’s going to be 4 plus 2 which is just six
so there we go there’s three examples of evaluating uh this function here
now um i’m going to um let’s see here we’re going to
work on five examples here and on this example first example here or example two
um we’re gonna we’re gonna evaluate some numbers um
find some points on the graph and then we’re gonna try to sketch the graph
and then towards the end we’ll use computer to sketch the graph if you want
to see that so stick around to the end if you can
alright so let’s see how to sketch the graph
so the first thing i notice is that it’s two lines here
this is a line with y-intercept one and the slope is two
but that piece is only good for when we’re strictly less than one

00:03
so i’ll just graph the line right here it goes through one and it has slope of
two so it looks something like that but at one right here at x equals one
we’re gonna have a whole and this line is only good this piece of
the graph right here is only good for less than one
now when we’re greater than or equal to one now the y intercepts at two
so we’ll need more up here so i’ll put a two right here um actually
the uh that’s the two right there and let’s see here when this is one what
is the height here when this is one the height here is um [Music] you know three
so this is looking like something like um
you know because even though we’re going to have a hole here i want to know what
this height here is going up to so what’s this height right here even

00:04
though there’s a hole there there’s a point missing right so
this one this piece right here was going towards the two plus one which is a
three and this is a one right here so two is going
to be right here in the middle and we’re going to have a y-intercept
for the second piece when we’re greater than or equal to 1
we’re going to have y intercept of 2 and a slope of 2. so it’s going to have the
same slope and then now when we’re greater than or equal to 1
means we’re filled in and then we’re going to take away this part right here
so i just wanted to make a good shape there but the point is is that when we’re
greater than or equal to one and and we’re possibly equal to one that’s why i
filled it in here we’re going to look like this line right
here which has y intercept two and slope two
and when we’re less than or equal when we’re less than one strictly less than
one so since it’s strict it’s open right here that’s not a circle it’s just
representing the fact that there’s there’s a point missing there so the

00:05
graph will look something like that so there’s the graph um for example two
there let’s see if we can go back to example one now so an example one here
um we have two different pieces also this time the um domain is broken up
into two pieces uh using the using zero so let’s look at a here will
be f of minus two and so what will f of minus two be where
where will minus two minus two be less than zero so i’m gonna use a minus two
in here so minus two squared plus one so that’s four plus one is five
and then for part b we have f of minus one
and again minus one is satisfying this so we have minus one with a square plus
one so we got one plus one is two and then we have zero right here so f of zero
so now which piece do we use for zero so

00:06
zero is equal to zero so now we’re gonna use this piece right here we’re gonna
get zero minus one which is minus one and then we have f of 1
and 1 is greater so we’re going to use 1 minus 1 we’re going to get 0
and then for the last part what happens when we substitute in 2 here
so we’re going to get uh 2 using this 2 we’re gonna choose greater
anchor to zero so we’re going to use this piece here
and we’re going to get a 1 here so here’s some examples of evaluating a
piecewise function you just take a look at what you’re plugging in and you see
which condition holds and you use that one now because this is a function only
one of the conditions hold in other words if someone put an equals right
here less than or equal to this is not a function then because when
you plugged in zero you would be getting two different outputs you would be
getting a one and a minus one and you know a function must have unique output

00:07
so that wouldn’t be a function right there so when you substitute in only one
of the conditions will be satisfied and we’ll use one of the pieces that
corresponding piece to get the output there
so let’s take a look and see if we can sketch this graph right here so first
off do we know what this piece right here looks like so if i just consider
this right here on its own what would that look like
so that looks like a y equals x squared but it’s been moved up one so it looks
something like this and what would we what would this right
here look like all on its own so that’s just the line
the slope is positive one it’s gone through the y-intercept of negative one
so it’s just the line going up like that so by themselves we have two different
functions and we’re piecing them together using this so um
when we’re less than zero we’re going to
look like this so here’s right here zero so when we’re less than zero now

00:08
we’re going to have a hole right here because it’s strictly less than 0.
we’re going to erase this part right here now when we’re
greater than or equal to 0 we’re going to look like this part right here so
what’s happening at zero we’re down here at zero minus one
and we’re just lines going up but we’re going to erase this part right here
and just put a tick mark there but make sure and fill that in because
at zero we are equal to -1 which is what we found right there
so this would be the sketch of the graph
and we’ll just erase that right there so this is the sketch of the graph of the
function f right here it’s a piecewise function to the left of zero looks like
this quadratic to the right and equal to zero it looks like this line right here
all right very good so let’s look at our third example now
so for our third example that looks like we have two quadratics

00:09
and we’re broken uh this function uh into two pieces so for the left we’re
going to be looking at this and for the right we’re going to be looking at this
so let’s see if we can sketch uh actually
before we do that let’s practice plug in some numbers
so minus two where does minus two fit in here it’s it’s we’re gonna use this
piece right here so we’re gonna look at minus two squared plus two
which is four plus two which is six and then for this one right here we have
f of one so we’re going to substitute in one
which condition holds this one right here so we’re gonna plug in one right
here so one squared plus two so this is three and then f of two right here
f of two will be where’s two fit in so two is greater than equal to one so
we’re gonna use this piece right here so
this would be two times two squared plus two right just plugging into 2 there so
that’s 4 times 2 which is 8 plus 2 which is 10.
so there’s plugging in some numbers right there

00:10
now let’s see if we can sketch the graph of this just by hand
and so we’re going to be broken up at 1. um so first off i usually like to um
you know make some little sketches over here you know what does this one right
here look like it’s x squared plus 2. so now we’ve shifted up two but looks like
a x squared graph and what happens this one right here
it’s two x plus two so it looks very similar
so it’s also been shifted up to but it’s going up a little bit faster so i’ll
just draw this one a little bit skinnier but they both go through two right here
so we’re breaking this up at one though so where would the one be so at one
where right here on this graph when we plug in one we’re going to get three
on this graph we plug in one we’re going to get something higher
right so we plug in one here we’re gonna get a four out all right so

00:11
there’s the two graphs separately now let’s try to piece them together
um and try to sketch the graph of f now not just the pieces right the whole
graph so we’re broken up at one and less than or equal so that means i’m
going to be filling in the the point at 1 but i’m going to be looking like this
right here which is going to come and have this right here so i’m going to
come in here and have this right here and this point right here is a two and
that’s a three now when we are greater than one we look like this one right here
um which is just you know going up like that but it’s going up like a parabola
it’s not it’s not like a line going up it’s got some some curviness to it so
we’ll come up here like this and now actually that’s not right though
because this is hitting at a four so let’s put a four here
and we’re going to have a hole here and then it’s just gonna go up so

00:12
you know sometimes people like to put these arrows here but uh this is filled
in right here and it looks just like a um i like to make it a little
pointier there something like that there and then this is open right here
so when we substitute in a one where are we going to go we’re going to
go to a three that that’s filled in right there
all right and when we go to a two you know then we get the 10
you know way up here all right so there we go there’s a sketch of the graph
of example for example 3 there there’s the sketch of the function and these
were just you know little doodles on the side we don’t need them anymore
so there’s a sketch of the graph of f all right so there we go let’s look at
another example now um number four so here we go let me erase this real quick
all right so number four here now we have three pieces

00:13
so this looks like a lot of fun this piece looks like a line this piece looks
like just a constant four and this piece looks like a parabola so we got these
different pieces here broken up by these
conditions over here let’s practice with some numbers first so f of two is minus
two we’re going to plug in minus two whereas minus two fit in it’s in right
here you always gotta check that you can’t just assume it’s the first one you
gotta check the condition so we’re gonna
get three times minus two and then minus one
so that’ll be minus six minus one so that’s minus seven
now let’s substitute in here a minus one half so where’s minus one half
fit in that fits in right here minus one half is between minus one and
one so we’re gonna get a four out and then uh what about f of three here
so f of three here is you know substituting in a three we’re

00:14
going to go right here so we’re gonna get out of three squared which is just
nine all right so there’s uh you know how we plug in
but now let’s sketch the graph of this and i’m going to graph each one of these
separately just as a little doodle over here it’s just a little scratch work so
the first one here is we’re looking at the y-intercept at minus 1 so it’s right
about there and then the slope is positive 3 so i’ll just make it go up and now
you know what are some numbers on here this it’s interesting around minus 1
right here so when x is the minus 1 right here what’s going to be going on
down here so minus 1 we’re going to have here we
didn’t plug in minus 1 but if we just look at this graph right here 3x minus 1
all by itself i’m not doing the whole piecewise yet but just this by itself
what happens when we plug in a minus one here we’re gonna get a minus four out
right that’ll be minus one times three so minus three minus one so
minus four so there we are right there so that’s an interesting point on this

00:15
what does y equals four look like well that’s just a horizontal line very boring
what’s happening here at minus one and one so minus one it’s still height of
four and at one it’s still a height of four okay
and now let’s look at one more piece right here the y equals x squared
this time there’s no shift on it so it just looks like a nice parabola like that
and where is it interesting where’s an interesting point on it what’s happening
at one so at one we just have the point one one
so there’s an interesting point on it all right very good so there’s our three
pieces and i want to know what each piece looks like before trying to sketch
the graph of this let’s sketch the graph of this piecewise function now
so we’re going to be broken up at -1 and 1.
so at -1 what’s happening to the left of

00:16
-1 i look like this right here so to the left i just have this line going down
here so we’re going to be looking like something like this right here this is
right here and it’s the line and the slope is three
and this is going to be here minus one and this is going to be minus four now
the question is do we fill this in or not since it’s strict right here we’re
not going to fill this in so i’m going to make that clear by putting
just a missing point on it it looks like a small little circle
all right so now what about between -1 and 1 well it’s just a constant it’s
just a 4. so i’ll go and draw my 4 across here
and this is let’s say a 1 and that’s a minus 1. and now you know do we fill in
or or put empty spots here right so these are both equal here so these are
both going to get filled in here and let me just label this a height of four

00:17
and that’s my one for my tick mark and here’s my minus one all right so um
what’s happening now greater than one so greater than one i look like this
parabola here it’s coming through here and what’s the
height coming in here it’s coming in here let’s move the one down here again
now so it’s coming in here about a height of one so it’s going to come in
through here it’s going to look like that but we don’t need to graph this
part of it it’s going to start right here and it’s just going to go up
so it’s just coming like that going through there like that just like
this right here it’s just going to go through here like that and now the
question is does it get filled in here or not it’s
strict so i’m going to put an open spot right here
and now maybe we want to like just shape it just make sure and don’t don’t make
it look like a line right so you know we’re going to come in through here like
that and it would look like a parabola all right so there we go there’s the
graph of f and there’s the piecewise graph right there

00:18
all right very good some people like to put arrows there in any case
there’s a sketch of f and i hope you’re getting the hang of it
and well let’s see one more example though on the next example we’re going
to have three pieces also so here we go let’s erase this
and while i’m racing i’d like to mention that this episode is part of the series
functions and their graphs step-by-step tutorials for beginners so check out the
whole series um the link is below in the
description all right so example five so
we got a line here a linear par a linear piece a constant piece again and a
quadratic piece again so i’m going to look at this piece right here four x
four minus five x and i’m going to look at this piece right here and i’m going
to look at this piece right here so these are just my scratch work here
so when i’m looking at this piece right here it’s got a y-intercept of four
and it’s got a slope of minus five so it’s going down right there
and then um y equals zero so that’s just the horizontal axis

00:19
and then this one right here is y equals x squared but it’s been shifted up one
so it looks something like that so now where some interesting
points on these graphs right here so this one is interesting around -2 so
what’s happening here at -2 so minus 2 we’re getting 4 minus 5 times -2
which is 14. so the height up here is 14. so this isn’t just scale right there
because this is a 4 and that’s a 14. but it’s the shape that’s important right
here um now before i go on with those um actually i forgot i wanted to get
started with the fun stuff let’s go ahead and plug these in and just make
sure that we’re okay with the function so -3 that’s satisfied right here so
we’re going to get 4 minus 5 times -3 so that’s 15 so that’s 19. 4 plus 15

00:20
and then for f of 4 4 is going to go right here so we’re going to get
4 squared plus 1 or 17. and then for this piece here we’re going to get
f of minus 1. so where does -1 come in it comes in right here so we’re going to
get out zero here all right so this is an interesting point on this
graph right here the graph of this line is just y
intercept four slope is minus five and because we’re going to stop looking
at it and we’re going to break it up at -2 i want to make sure and understand
that point right there y equals 0 is plain and boring but it’s
only good between -2 and 2’s we’ll we’ll just plot those points there
all right and then this one right here it’s interesting around two what’s
happening around two so two i’m going to plot the point here

00:21
what’s the height on this graph uh it’s a five right 2 squared plus 1.
so there’s an interesting point on this graph all right so now that we’ve done a
little bit of scratch work and we’ve done some evaluating let’s go ahead and
sketch this piecewise function right here here we go
now we’re gonna be breaking it up at minus two and two so let’s go ahead and
see if we can plot those right now let’s
just put a minus two and two and see how it goes
all right so less than or equal to i’m gonna be looking like this line right
here so um we’re gonna be looking at the line to
the left and it’s just this part right here
and so i’ll plot this point right here this will be a height of 14
and we’re just going to put that line up there right there there it is so that’s
the that’s the branch that’s coming from the 4 minus 5x right there
and now between -2 and 2 is just right on top of the axis
i’ll just shade that in a little bit so you can see it
now what about how it’s connected right here both of them cannot be filled in

00:22
because it’s a function so at -2 this piece is going to
be the important part so this will be strict right here so it’s open so i need
to put an open spot right here and same thing for right here this is
open right here and now at two i’m at five for this
piece right here when we’re greater than or equal to two
so two i’m at five let’s put a five down here
and then i’m just shaped like a parabola
again so here’s the 0.25 and i’m filling it in because it’s equals and so it’s 2
5 and i’m just going to be shaped like some kind of like parabola
in fact i might want to flatten it out more just to make it look like it goes
through the origin there or actually goes through through a one but any case
there’s a let me make that a little bit straighter all right so there we go

00:23
there’s the um that’s supposed to be straight and
that’s curvy because that’s a quadratic and then it’s constant right there
all right so there we go so now let’s take a look at how to generate these
graphs using a computer so let’s switch over to python and while
we do that let’s erase this board here real quick all right so let’s get some
um python going here so we’re going to open up a python notebook and here we go
now if you if it’s your first time trying to
use python i recommend using the link below in the description
and that link will take you to a google document where you can open it up and
run a python notebook it’s free and it’ll open up and it’ll save it on
your google drive automatically but you’ll be able to run this code and

00:24
you’ll be able to follow along so let’s see what the setup here is
first so you’ll want to type everything up in here
into the python notebook again the link is below in the description just click
on the link and then that click i think you click on a new notebook and once you
do that then you’ll be able to start typing things in here so the first thing
we want to type in are these packages right here this allows us to do the
following work so i would just type up this right here this import and this
import and this import and once you type those in just like they are then you
just hit shift enter on your keyboard okay so um now i’m going to be making
some sketches some graphs and i want my graphs to look like they
look like in a in a math course not like they look like and by default
for python so i cooked up this uh function right here called pc axes
and so if you just type this in now this is optional you don’t have to use this

00:25
right here but this pc stands for precalculus axes and this allows me to
make my sketches when they come out to look a certain way
all right so let’s look at our first example so this is example one that we
did earlier and so here’s how we would define a
piecewise function or this is one way at least so i’m going to define a function
f of x so again you need to type in things exactly as they are spaces and
everything these tabs or whatever all right so we’re going to define this
function f of x right here and we’re going to say
if the condition x is less than zero then we’re going to return x squared
plus one so that’s an x squared and then a plus one
if the condition is greater than or equal to zero then we’re going to return
the x minus 1. so this is defining this function right
here notice it’s quick and easy doesn’t take very much work at all
in fact the harsh part is probably to get the notebook started
all right and now we’re going to make a plot and so this is how we would make a
plot now i want to run through this here

00:26
very briefly at least for the first time so that you can see what you can
and or what you might want to customize so first i’m going to define a figure
and then i want to define a set of axes to go on my figure
then i’m going to customize my axes now as you can see my axes have arrows right
here and right here and the axes go through the origin
so by default the python doesn’t do that so if you if you like the default way
python gives you graphs then you don’t have to use this line right here
but i like to have my plots looking like this
all right so now we’re going to specify the domain
now this is where there’s some trial and error you know because there’s no
nothing up here that tells you where where to look at this function all
it says is there’s it’s broken into pieces at zero
so i’m going to look a little bit to the left to zero and a little bit to the
right of zero minus 1 is the left and then 1.5 is the right

00:27
then this right here tells me what kind of steps i’m going to take it into so
the 0.001 tells me when i’m sketching this graph
right here or when i’m looking at the domain
i’m going to take it into little tiny broken steps
minus 1.1 and then minus 1.1 plus this little break so it’s going to plot
tiny tiny little points and it’s going to connect them together with line
segments so this way if you use a nice uh increment right here
it’s going to look nice and smooth so if you if you choose this larger then
you’re going to be able to see it’s going to be broken into line segments
however if you choose too many zeros then you’ll make your computer work much
harder than necessary but any case these
values right here you may want to change depending upon what function you have
we’re going to do some other functions down here and we’ll change our domain
what we’re going to be looking at all right and so then after that we’re

00:28
going to say what the y’s are we’re going to use the function f right here
right here to make the y’s and then we’re going to plot all the x’s and y’s
and then we’re going to show that plot so that’s how this code works
so i’m going to execute that and then we
get this sketch right here so this looks like the parabola over here
and this looks like the line over here so that’s we got right here we got the
line right here and we got the parabola right here and
it all looks great except for the fact that python doesn’t
put in the holes like we did so this was strict right here so we
actually put a hole in our graph right here so we put a circle right here
so by default python doesn’t do that so and then this right here is equal so
this would be filled in right here so python didn’t do that the way we did
that by hand moreover python actually tries to

00:29
connect these two points you can see just a slight tint of green so python is
actually trying to connect those two points in fact if you change our
step increment right here so now it’s going to be much more coarse
so now it actually tries to connect them and that just
gives a bad representation of this of the graph
so i’m going to throw in a couple zeros here you don’t want to throw in too many
or your machine will get bogged down all right so there’s a sketch that we’re
going to end up with and this gives us a reasonable
approximation to the sketch that we drew by hand in the sense that
yeah it’s the same formulas here but it’s not going to tell us the
inequalities where it should be filled and not filled
all right so now let’s look at example 2 that we did
so here’s the function right here we’re broken up at 1 and greater than or equal
to 1. so that’s my conditions right here
if x is less than one or if it’s greater than or equal to one

00:30
and for this piece it’s two times x plus one and for this piece it’s two x
plus two so i define my function and then i use the exact same code here
i didn’t even bother to change the window because for this window right
here it turned out to be nice also um so to the left of one we have this
line here and to the right of one we have this line right here
and you see it tries to connect these two so it shouldn’t be connected number
one number two the lower line should have a open
right here and it should be closed right here
and that part right there shouldn’t be there so the drawback of using a
computer program is sometimes you have to interpret the results on the other
hand it gives you the plots pretty fast doesn’t it i mean it doesn’t take long
to type that up and to execute the cell and then you get the graph in a split
second for more complicated graphs this could be of great value

00:31
all right so let’s look at example three so we had x squared plus two
when we’re less than or equal to one so x less than or equal to one we have x
squared plus two and greater than or equal to one
we have two times x squared plus two and then i use the same window minus one
to one point five and i use the same step and so let’s execute again
there we go we look like this nice parabola coming through here and then
it should be and then we have this nice parabola
going right here now it may look like a line but it’s not it’s a parabola you
can tell that by the equation up here at one we’re broken up into pieces
greater than one we’re strict so this should be open right here
and this should be closed right here all right and then for the fourth
example right here we’re broken into three pieces
so we’re gonna have if x is less than minus one

00:32
if x is between minus one and one if x is greater than one and then i just
typed in the formula three x minus one that’s what we’re going to return two x
times plus two oh actually that should be a four right there and then
and then the last one is the x squared if we’re greater than one so let’s hit
shift enter and execute that and here we go now
this domain here minus one isn’t great choice because we don’t get to see this
branch at all so let’s change this to say a minus two and see how that works
all right so then we can see a little bit more of it we got this line uh right
through here um and the slope is one y intercept is
minus one right so it’s coming right through here it’s going to go through
your minus one but it has to stop right here and it’s strict so this is open
right here and these are equal so at four this is

00:33
going to be filled these are going to be filled in right here and again you just
have to ignore this part right in here that’s not part of the graph
and then we have a height of this is filled in also and then now right here
this is strict so this is open right here and so again this is not part of the
graph so this will be the graph if we were graphing this by hand like we
already did and then this looks like a parabola
coming through here right there so that’s the graph that we we did by hand
right there earlier all right so number five the last one
all right so uh less than or equal to minus two we have four minus 5 times x
between minus 2 and 2 and it’s strict here so we have it strict here
and then greater than or equal to 2 and then we have here the x squared plus 1
and now let’s hit shift enter on that and let’s see if our domain worked out
i use minus four to four so minus four to four

00:34
and so here’s where the four minus five x is coming in
and here’s where we get the x squared plus one coming in right here and then
in between it’s just a zero so it’s just right on top of the axes so this one
right here would be filled in this part right here
and this right part right here would be filled in
and then it’s on top of the axis so it’s
it’s too hard to see by computer so i’ll just draw that in for us right here
and then this was open and this was open and that was the graph that we had
before coming in here like here like a parabola and then this part right here
coming in here like a line right there so there’s how we would sketch the graph
uh using computer and by hand and uh i hope you enjoyed this video and
i’ll look forward to seeing you in the next episode
if you enjoyed this video please like and subscribe to my channel and click
the bell icon to get new video updates