# Using Transformations to Graph Functions (Using Python)

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

00:00
in this episode you’ll learn how to apply transformations to simpler
functions to graph more complex functions we’ll do this using the python
programming language to make things really easy let’s do some math [Music]
hi everyone welcome back so um we’re going to start this episode off by
recalling what the parent functions are um some people call these toolbox
functions or parent functions but in any case uh we will have eight of them the
constant function the identity function the quadratic function
the cubic function the absolute value function the square root function
and the cubic function the cube root function
and the reciprocal function these are called the parent functions
now in the previous episode parent functions and

00:01
we went through these one by one and we graphed them by hand and by computer we
stated the domain and range and we explained the shape of them so
i recommend checking out that video that episode right there
now uh keep in mind though that this episode is part of the series
functions and their graphs step-by-step tutorials for beginners so that’s where
you’ll find this episode and this one right here where we already talked about
these parent functions right here so if you already know what these functions
look like then you’re ready for this episode right
here if you don’t know what these functions look like graphically then you
want to check out that video right there and also in that video that episode we
talked about how to sketch their graphs using python and so we’re going to
continue that study by looking at by recalling what’s in this video right
here also shifts reflections and scalings so in this video we talked

00:02
about how to apply transformations to these functions such as vertical and
horizontal shifts or reflections and stuff like that so also
want to check out that episode there now in this episode
we’re going to take what we learned in these two episodes right here and we’re
going to apply the python programming language so we can see how the
transformations of these work and we’ll be able to put some widgets on them so
you can kind of animate them and you can kind of see how this all works together
so let’s get started we’re going to go to the python notebook right now
now if you don’t know how to open up a python notebook
i recommend checking out the link below in the description
it gives you a free python notebook that you can click on right now and get
started so you can follow along you can type up all the commands and you can see
how it all works so i recommend doing that rather than
just following along and watching although you’re certainly able to watch it

00:03
let’s zoom in here a little bit so we can see this a little bit better so the
first thing is we need to have a setup now you don’t need to type in this cell
right here it’s just to help us stay organized but wherever it sees an input
you need to type in without all that right there so the first cell right here
is to type in the packages that we need the python packages that we need that’ll
make things very simple so this right here has a nice package and we’re naming
it plt for short but it has a lot of code in there to use
and then we’re going to import some pi numpy pylab and we’re going to import
some widgets here yeah so type all this in here and then
once you do that you’re going to hit shift enter on your keyboard make sure
you type it exactly as shown right here now if you’ve watched previous episodes
you know that i like to customize my axes so i’m going to use this function
right here this definition and i’m going to hit shift enter to execute all this
code so you want to type it up first and then execute that code

00:04
all right and then there’s the setup once you get those two executed then
you’re ready to go so what we’re going to do is we’re going
to talk about our parent functions the linear the quadratic the cubic
absolute value square root and cube root cube root function so we’re going to
look at each one of these and look at the transformations with those so first
thing is to define our linear function and we’re going to have an a an h and a k
and so the a is going to combine together the reflections and the
vertical compressions and and things like that so that’s going to be the
scalar out front there the multiplier out front and then we’re going to have a
h right here and a k right here and so we’re going to have a um
a definition of a linear function right there um now
i’m going to change this to a positive right there let’s change that to a
positive right there so i’m going to execute that cell so this is going to

00:05
plot for us a linear function so you can see how it’s linear right here i have a
horizontal shift right there and then we have our scaling
and then our reflections and then we have our vertical trend vertical shifts
right there so there we go i’m going to execute that and then i want to execute
this widget right here which is going to allow us to interact with this function
right here that we just defined we’re going to be able to interact with it and
we’re going to give it some values so i can interact it by changing h
between minus 20 and 20 and the defaults in the middle
and the k will go from minus 20 to 20 and the a will go from minus 10 to 10.
so the a the number in front here will go from minus 10 to 10. so let’s execute
that and then we get the sliders and we can interact with the graph now now by
default the a is zero which means this is just zero right here

00:06
and by default the k is also zero so we’re just getting the zero right
there right on top of it you just barely see it so let’s go and say graph
something like y equals let’s put it up here let’s say y equals
let’s say minus 2 and then we’ll do x plus 3
and then we’ll say minus 7 right there so what if we want to graph this sketch
right here so we’ll need to move the a to a minus 2
so we can bump this over here and i need to move the h to a
so we’ll bump this over here it’s a little bit too much
and i use my keyboard to move it over by one or two
and then the h so i’m going to click on this right here and
use my keyboard to get it right there so there we go there’s that equation right
there boom there it is right there and you can see that
uh what happened is we have the minus so it’s been reflected

00:07
because the parent one is y equals x which is going up this one’s been
reflected it goes down it’s been shifted over there so
using these a h and k we can shift around and we can just you know shift it left
and right and we can shift it up and down that’s kind of fun to do that
and we can we can scale it so now now a is just a one
and so how would you graph the parent function
just y equals x right so that would be when a is one [Music] and the h is zero
and the k is zero um [Music] so there we go
so that would just be the regular parent function there

00:08
all right so now let’s go on to the quadratic functions
and i’m going to change this to a positive also
all right and there we go so i’m going to execute this right here and so this
is exact same as we had for the linear function but this is a quadratic
function the only difference is this part right here i have an a
and then this is x squared plus h plus k and actually that’s not right let’s go
here and take that out it’s x plus h and then a square
and now let’s execute that so this will be horizontal shift and then apply the
function and then apply the reflection or scaling
and then add the um vertical shift up or down last so there we go so let’s
execute that and now let’s execute this right here

00:09
and this widget right here so we can interact with it there we go perfect
so now this one right here again a is zero and by default and the k
is zero right in the middle there so at first i’m just getting the 0 right there
so let’s get this one when a is 1 let’s bump a up to 1 and then we’ll leave
the k at 0 and the h at 0. and so this is just the graph of y equals x squared
right here this is just the parent function right here
and so if we want to graph something like let’s say minus 4 and then x minus 3
squared and then plus 5. how would we graph something like that right there
so now the a here is a minus four so we can move that over to minus four
and then the this is a minus three here so let’s bump that down to minus three
and then wrong way there minus three i said minus three there we go and then

00:10
uh plus five we can bump this over up here to five
there we go so there’s the sketch of this graph right here as you can tell it
has a little bit above the x-axis right there so anyways there’s
the graph of that right there so using these sliders we can do these values
right here and i’m just using default values you can you can change the
increments right here so right now they’re just integer values right there
but you can change the increments of those right there and play with this
some more so there’s the quadratic one so now let’s look at the cubic one
and so here’s going to be our definition of cubic
now i’m going to change this here again this should be a positive and again the
cubic should come after the horizontal change here
so let’s execute this cell right here so this is going to be defining a cubic
function it’s the exact same code for the linear
and quadratic the only difference is this is a power 3 now

00:11
so now let’s execute this widget right here
and let’s sketch the graph of the parent function
which is when a is zero or sorry a is one there’s two let’s go to one right here
so there’s our function right there there’s our parent function y equals x
to the third right there coming in nice and smooth right there
and now let’s say we want to graph something like y equals say
let’s go with minus minus 4 and then x minus 5 squared or cube and then
minus 11 right there so what would that look right there how would that look
right so now the a is -4 so i’m going to move this down to -4 right here and
then i’m going to say the h here is -5 and then the k here

00:12
which is coming last is a minus 11. all right so there we go
right there and so there it goes right there
and that’s just on the graph from -10 to 10
and there’s going the graph right there so you can see
that it’s been shifted down now you know maybe it doesn’t look like it
shifted down but if you look at the scale here then
you can kind of see these these are really large numbers right here so it’s
hard to tell that it’s been shifted down by 11 but if you look at the at a
different window you’ll see that that you know that’s actually been
shifted down by -11 and it’s been shifted right right because it’s a minus
so it’s been shifted right by five units so it’s going right through there and
it’s going through minus 11 right there all right and you know -11 looks really
close to the x-axis when the scale right there is so big right there

00:13
all right so there we go there’s that function right there and you know we can
we can say how big can we go here go up to 20 right there
so now even 20 looks still close to the x-axis compared to 2000 right it’s been
shifted up right there all right um of course if we want to we can
say k can go to say 100 execute that let’s move this to minus 4 again
this is just fun to play with aren’t they minus 4 and then -5
and then now the k let’s say the k is something interesting [Music]
so how about 200 so we’ll say plus 200. all right so how
do we graph this right here minus 4 minus 5 200 and we can see it’s been shifted

00:14
and then it’s been scaled and now instead of going up like this
it’s been reflected so now it’s going down like this right here and you can
see it’s been shifted up but it’s still a little bit hard to see it because
it’s still a factor smaller than the first tick mark along here and that’s
because we’re using -10 up here as our window and that’s giving us a really
large value up here all right so there we go there’s our cubic
and so now let’s look at what we have next will be the absolute value function
all right so here we go let’s define the absolute value function
we’re going to plot it and we’re going to have here i want to
move this to a h is positive here and so i’m going to be taking the
absolute value of x plus h and then plus k and then here’s our a right here
so make sure that we’re not taking the absolute value of x and then plus h
you know this is a horizontal shift so it’s x plus h and then the absolute
value right there all right so good so here’s our widget right now so we can

00:15
play with it here we go i executed that cell right there
and now let’s graph our parent function when the a is 1
and there we go so this is the graph of y equals absolute value of x
when the h is zero and the k is zero so you can think about it as
one times the value x absolute value of x plus zero plus zero right just
absolute value of x all right so anyways
um what happens if we here to shift this around a little bit
get something that looks nice that’s shifting it so far over you can’t even
see the second part of it so let’s move it over down a little bit
there it goes and then let’s move this here maybe up
so this would be the sketch of the graph of so the a is 2
and then absolute value of x plus minus 4 so minus 4 and then x plus nine
so here’s the sketch of that graph right there a nice pretty sketch right there

00:16
and we can play with this right here we can play with these numbers in here
to sketch pretty much whatever you want all right and if you don’t like the
window that you’re seeing it on you can come back up here and re-execute this
right here and give it a different window so you know it’s around a four
so maybe we don’t want to go all the way
to -10 right so we can come back up here and say the window is say
i don’t know minus six something like that so we can re-execute that and then
shift-enter and re-execute that and then of course we have to move our a
a values back over here so a is two and this is a four and then this is a nine
so now the window just goes to -6 right there
so this is the same shape same absolute value though

00:17
all right so now let’s look at some square root functions
and so let’s see here we’re going to have the square root function right here
and so we’re going to take square root and then i’m going to say i’m going to
say this is a plus h right here and i’m going to shift enter and execute
that definition so now we have the square root function defined
it takes in some parameters so the a and the h the k
and then i’m going to execute this right here this widget right here
and now let’s get our parent function when the a is one and the h and k are zero
and so let’s go back one there we go so there’s our square root of x there’s our
parent function right there and so let’s just play around with it
what happens if we go negative so now it’s going down
and what about if we shift it to the left to the right

00:18
all right so yeah when i shifted it to the left
it came up with an error on that range right there so let’s come back here
and shift it and we can shift it say up so what would this be the graph of right
here so this would be the graph of minus six and then we’re doing square root
and then this would be plus 11 right here so this would be the sketch of this
graph right here right through there all right sweet so now let’s do cube
root function right here let’s do one more here
all right so we have cube root and i want to change this back to a plus here

00:19
and so i have cube root all of x plus h and all that is times the a
and then plus k for the vertical and so let’s plot that there we go we
defined the cube root function i executed that cell right there and now
let’s come over here and let’s execute this widget to interact with the cube
root function um and there we go so let’s jump back down here
so we can see it there we go so cube root and the widget and now let’s graph
our parent function the basic cube root function right there
so there we go it’s coming here and it’s
getting really steep and then it’s steep and it’s slowly coming out of it there
we go and so this is the graph of y equals cube root of x the parent function
and now we want to do some transformations to that so we can do a
reflection right there so that’ll be a minus 3. that looks nice
let’s say move it to the left right there
and then let’s move it down right there and so this is this this right here is

00:20
the sketch of y equals and then we’re doing a minus 3
and then we’re doing a cube root of and we shifted it uh to the left so x
plus seven and then we shifted it down so minus
seven right there and so there’s the sketch of it right there
and so there’s the point right there about minus seven right there
minus seven minus seven right there about
so you can kind of see about minus seven right there
all right so yeah that was a lot of fun i hope you enjoyed this uh episode and i
hope you uh you know enjoy using python like i do
just to kind of play with it and see what see what we can learn
the next episode thanks for watching if you enjoyed this video please like
and subscribe to my channel and click the bell icon to get new video updates