# Graphing Lines and Circles (Using Python)

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

00:00
hi everyone welcome back i’m dave uh let’s see what’s in the episode today
so today we’re going to talk about lines and circles and we’re going to be
working in python getting a good understanding of how to do these things
in python so we’re going to talk about linear functions we’re going to talk
about finding the slope between two points and solving the point uh solving the
problem that we’re given a point and another line
and we want to find the line that’s parallel
or perpendicular and then we’re going to work with circles in standard form and
expanded form and we’re going to do all this with python now before we get
started i want to say that this video is part of the series functions and their
graphs step-by-step tutorials for beginners the
link is below in the description and so i hope you check it out check out the

00:01
full series below let’s get started all right so here we go we’re going to
start off with talking about linear functions
and so we can sketch this graph right here um very simple
we just mark off at 54 and then we say the slope is 2.
and now for if we have something like this one
then we’ll first need to solve this for y
so to do that i’m going to move this 3x over and then we’ll divide by -2
and so now we can sketch the graph by simply doing this the y-intercept here is
right so we can make this be um move the three x over
so this will be three over two and then minus three over two
so minus three over two and then slope is positive so we can
sketch the graph if we solve this for y right here so this is a linear function

00:02
and part a it’s already a linear function and so then we have a third example
right here that we’ll also look at so let’s look at this in python now how
would we do this in python now when we get to set up right here
you know check out the link in the description to get a python notebook
started like this one right here and so what we’re going to do is we’re
going to get a setup going here and we’re going to import
a couple packages so that our python is easy to work with so we’re going to
import matplotlib numpy senpai pi lab and we’re also going to import some
widgets we’re going to work with some circles later on
so these are all the packages and these are all the imports we need for this
video so i’m going to shift uh enter execute that
now if you’ve watched the previous episodes you’ve seen this definition before
this is for pre-calculus axes this is the way i look like my axis to look so
this is a customization right here function right here

00:03
that we’re going to use in our plots right here so they come up looking nice
for us all right so now let’s start looking at some linear functions here so
we’re going to sketch the graph of this line which we just which we did just a
second ago and so i’m going to execute this code right here
now just briefly what does this do it’s declaring a figure and some axes and
then i’m going to customize those axes so that i have arrows over here and here
now i’m going to guess on some range for the x’s and i’m going to guess from -5
to 5 and so i’m going to that’s done by trial
and error and then 0.01 are the steps the little increments between the little
points that we’re sketching and then i’m going to sketch my linear
function right here so 2x plus 54 and i’m going to plot it and then i’m
going to show it so let’s execute this right here
and we get this graph right here so it’s the same thing that we just did by hand

00:04
here’s the 54 and then the slope is 2. okay so now let’s move on and sketch the
um example uh b right here or the second one so three x minus two y equals three
so i’m gonna do the same exact code here and but the difference is now this is
gonna be y equals and this is what we got when we solve this for y right here
so here we have the um you know negative
three halves and then we have a slope of three halves right here
okay and so then we’ll do example uh the third example right here that we saw
minus five x plus y equals minus two again i’m going to solve that for y in
this case i just need to move the minus five x over we move it over there and so
we have this solve for y right here and so i’m just going to do this from
minus one to one i found that by trial and error you
always find the domain by trial and error alright and so then there would be our
graph right there all right so there’s a nice

00:05
one two three four five six six lines of code you can get a nice quick graph
of python in python right there of your function right there
so now let’s go back and um you know now that we did those three now let’s go
back back and look at finding the slope so just to recall very quickly remember
how to find the slope we’re going to do 4 minus 2
and then we’re going to do 9 minus 3. and so we’re going to get 2 over 6 or in
other words 1 third and so we can find the slope if we input
two points we can find the slope very quickly so let’s see how to do that on
python let me erase this real quick okay so uh using this in python let’s go
over here now and so i’m going to define this function
right here so i’m given the point here x1 y1 and i’m giving another point here
x2 y2 and then here’s the slope formula right here
so we can find the slope of the line that passes through these these two

00:06
points right here 3 2 and 9 4. so this function right here assumes that they’re
in this order right here you can define or rearrange them in your definition
here of course then you would have to adapt your formula right here
so any case let’s go and execute this definition right here
and then now we can find the slope and as we saw a minute ago it was equal to
one-third this of course is just an approximation because
these threes go on forever all right so here we got the slope
between these two points here and we’ll just execute that real quick minus one
and now the slope through these two points right here and we’ll execute that
real quick and we get this right here and if you
want to find out what the exact value for that is then we could just get it as
a fraction if we wanted to do that okay so um now let’s switch things up a
little bit now let’s do a little bit more than just um you know

00:07
start with two points so what if we’re given the slope and the y-intercept let’s
plot the line here so here’s a new function
given the slope and y-intercept we want to show the plot right so
again we declare the axis and the figure and then i’m going to customize my axes
and then i’m going to make a default window right here minus five to five
let’s execute that and we’re going to graph this line this
linear function right here we’re given the slope we’re given a y-intercept here
all right so we can execute that and now let’s go ahead and
execute this function right here also this is slope intercept so this takes us
two points right here just like we did before and we’re going to find the slope
and now we’re going to find the y intercept b
so where does this y intercept b come from right so the line has an equation y
equals mx plus b so if you know the m and you know a point say say we know the

00:08
point x1 y1 then we can come in and solve for the b so the b would be equal to
[Music] right just move the mx to the other side
so that would become minus now minus m1 x
equals b so that’s how we’re getting the b right here in this formula right here
it’s y1 minus m times x1 and then we can plot the line we can use
this function right here now that we know the slope and the y-intercept and
we can use this function right here and we can plot it and then we can also
return not only the slope but the y-intercept
so this function right here which uses this one
built that we just defined it uses plot lines so we’re using it right here but
this is a nice function right here because we’re given these two points
right here and it’s going to show us the plot and it’s going to return the slope
and the y-intercept so let’s execute these two functions right here and

00:09
there we go so now not only are we going to find let me erase this real quick so
now not only are we going to find the slope that passes through these two
points so i’m going to go back through these examples real quick again so
here’s these two points and instead of just finding the slope function
i’m going to use the slope intercept function right here so this will tell me
a this will show me the plot and it’ll return the slope remember we
got one third and it returns the y intercept also right there so that’s
what this function right here does slope intercept you just type in a point so
let’s use it again so this was part b right here so let’s do -1 2 3 and then -2
execute that real quick and then there’s our slope and here’s
our y-intercept and here’s a plot of the line that goes through those two points
right there and then for our third example

00:10
here we go let’s execute it right here and then we have our slope and our
y-intercept and again these are approximations but it’s nice to be able
to quickly have a plot right there and to visualize it all right so
now let’s look at what’s next all right so we did these three examples
here and now we’re going to switch the problem up here a little bit
so find an equation of the line in slope intercept form
that passes through the point and is parallel to this line right here
so we want to be parallel to this line right here so what does that mean
so how do we find the slope of this line so we got minus 3y equals 5 and then
we’re going to move this 2x to the other side
and then i’m going to divide by the minus three
so five minus two x all over minus three and then if we want to put it in
y-intercept form we can just simply simplify here so this will be two-thirds x

00:11
and then minus five thirds so this would be the slope right here
because we want to be parallel to this line so the line we’re looking for needs
to have this slope right here so we can go find the line now
because we know a point so y equals mx plus b we know the slope is two-thirds
and we know a point two minus one so minus one is for the y and then x here is 2
and so this will tell us the y intercept here so this would be -1 equals 4 3
plus b so minus one minus four thirds equals b
and so then here now we’re going to get minus three over three minus four thirds
and so here we can say b is what minus seven thirds
and so the equation that we’re looking for or any equation of the line that

00:12
we’re looking for is two-thirds x plus the b which is minus seven-thirds
so there’s the line right there for part a here’s how we do this mathematically
and now we’re going to see how to do this in python
and we’ll do some more examples too here here we go
so let’s switch to python view and erase this okay so now we’re going to
solve the point problem here point and parallel line
so we’re going to find an equation of the line that’s what we’re looking for
and we want to return it in slope intercept form and it passes through the
point and is parallel so here’s this function that’s going to
work right now and let’s um you know make sure we understand this so
i’m going to be given here a point and a parallel line
so if we look back here at the math view

00:13
right here so we have this right here we have ax plus b y equals c
and so we’re given this right here so we’re given this 2 3
and 5. so that would be the a b and c right there so we’re given this a b and c
and we’re given a point okay so the slope is going to be the minus a over b
and the y-intercept is going to be the b and we showed how to find that that’s
going to be y 1 minus the slope times the point
and then i’m going to declare a figure and
customize it and i’m going to set here as my default right here minus 2 2
and then my step and so now i’m going to graph the original function and the
um parallel parallel func the parallel line that
we’re looking for and i’m going to show legend so that we can see the difference
and then i’m going to show it and then we’re going to return the slope and the

00:14
y-intercept of the new line that we’ve been looking
for so let’s execute that and here’s our first example right here
so we’re given this point right here and the line we’re looking for is parallel
to this line right here we want to be parallel
so we’re going to execute this function right here and then there we go
so the original is in this green right here and the parallel line that we were
given is this one right here um i’m sorry the
parallel line that we found is this one right here
and so as you can see here it’s minus 2.3 right right about right there
and then the slope is two thirds right there so we’re just going up right there
like that all right and so now once we write this
function one time now we can execute it and solve multiple problems right here
so we’ll execute again we have minus 2 2 and we have this line

00:15
right here so our a is 1 b is minus one and c is four and so here we have the
original line and then um then the line parallel to it is this one right here
all right very good so then the last example right here oh and here’s the y
the slope and the y intercept so we got the y intercept going right up
here at three and the slope is one all right so one last example real quick
all right so we’re given the point of four minus five and we’re given the a is
minus three and the b is two and this is minus seven here
and so the original line is right here and the parallel line to that is um
the slope is 1.5 and then this is minus 11 right here for the y-intercept
all right very good so now we’re going to solve the same problem again
but this time instead of finding um we’re going to be given a point the same

00:16
thing but this time we’re going to be perpendicular to a given line so
this is going to be pretty much the exact same function right here with a
minor difference is the slope is going to be different
so let’s go back to the math um right here and see how we would solve
this right here so um a minute ago you know we solved
this for y right here right so this is exact same problem the only difference
is it says perpendicular here so if we solve this for y again so i’m going to
say minus 3y equals 5 and then move this 2x over so minus 2x
and again we’re going to divide by minus three
and so let’s see here what did we get we got two thirds x
and then minus five thirds and so this was the slope this was the
exact slope we needed when we were going
to be parallel but right now we’re going
to be perpendicular so we need the slope we’re going to take the negative

00:17
reciprocal of this so negative 3 over 2. so this is the slope we’re going to use
to be parallel sorry to be perpendicular to this line
we don’t want to use the exact same slope of this line we want to use the
perpendicular one so let’s go back here and see how to do this in python so it’s
basically going to be the same thing we’re going to define the same function
right here um but this time instead of using minus
a over b we’re going to use the reciprocal a over b with it with a minus
so it’s like minus minus right but anyways whatever after we find the m
then we find the y-intercept the exact same way we customize our axes
and i’m going to put both plots on this one right here
and i chose this right here to be my default um
window right here for the examples that we’re going to do
and so then i’m going to plot the lines right here
all right so here’s our first example so we have the same point in the same line

00:18
that we had before and now when we exec execute this code right here so we have
the original uh line and then this is the new line that’s perpendicular to it
and i’m returning the slope and the y-intercept so you can see the y
intercept is at 2 and the slope here is at minus 1.5
all right very good so now let’s execute this code again
and this time we have the example b and so now we got the original and the
perpendicular right here and then let’s go ahead and execute it one more time
for this third example same point and same line that we did
before but this time now it’s perpendicular so we got this point and
we got this line this line right here and so as you can see we’re going to be
perpendicular to it right there so we have the y intercept is minus two
thirds or minus 2.3 right there and then the slope

00:19
is going down right here so minus two-thirds for the slope right there
all right very good so now let’s start talking about circles so here we go
so circles um don’t forget uh this episode’s part of
the series functions in their graph so you can check out all the episodes
in a previous episode we talked about circles so now i want to talk about
circles but now we’re going to be talking about using them in python right
here so here we go so circle is in standard form so we’re going to have a
h and a k that’s going to be the center and r is going to be the radius and so
here’s two examples that we’re gonna do right here the when the center is at
zero zero and the radius is four and when the center is minus seven minus
four the radius is seven so you know we can sketch this by hand we can say
for example the first one right here it’s centered at zero zero right here

00:20
and so we can we can um center that right there and then the radius will be four
so something like that right there the radius is four
and so this equation would be x minus zero squared plus y minus zero squared
equals the radius squared right so this would be x squared plus y
squared equals 16. so for example a right there
all right and so let’s see how to do this in python circles in standard form
so now we’re going to be looking at this problem right here so um
you know we got the center and we got the radius and we got this equation
um so we’re going to write this in standard form

00:21
and sketch the graph all right so here we have
this function right here which we are defining graph circle and we’re going to
input an h and a k and an r and we’re going to define some axes and
then we’re going to customize this and i’m setting my aspect ratio right
here at 1 so that it doesn’t look like an ellipse all right so now i’m going to
make up this circle right here um and we’re going to use the plt the
the map library and we’re going to call it circle and we’re going to do the um
center and the radius we’re going to color it a little bit and then make it a
little bit transparent right there so that’s a pretty nice circle right there
so let’s execute that code right there and voila we have a nice function that’s
going to graph all of our circles for us so example a we sent center 0 0 radius

1. so there’s a nice sketch of the graph right there

00:22
and now let’s move it around so now the center is at -7 minus four and the
radius is seven so let’s execute this code right here all right there we go
so now the center is about minus seven so we moved over here to
there and then the radius is seven all right and so
now let’s look at some translations here so
notice that i’m sorry as h and k change how does the graph of the circle change
let’s go back here and look at some translations so as h and k change how
does the graph of the circle change position
so in order to study this problem right here we’re going to use a widget and
let’s execute this code here there we go so this is widget dot interact and then
we’re going to interact with the graph circle that’s the function that we just

00:23
made up here uh yeah graph circle is this function we just defined up here
and we’re going to say the h can vary between -10 and 10
it’s currently set at zero and k can go in this range it’s currently set at zero
and then the radius can go from zero to fifty
so and it’s currently at twenty five so and here’s the graph what we get
and then let’s just slide these over so right so what happens if we change right
so we’re studying this equation right here the x minus h squared plus y minus
k squared equals r squared so if we change the h
right here that’s a change in the x so you should see it move back and forth
along the horizontal axis right here so i can change it like that so now the
h is seven so this this is what it would look like if we were graphing this
equation here x minus seven plus y and then we still have the k at zero so

00:24
that would just be a y squared and then the radius is at 25. so this
would be 25 squared which is what 25 squared is what 325 25 squared is 325.
anyways um this would be like the circle right here
we can um you know move the radius all the way down to 1 and we can move the k
so there k is 2 now so now this equation would be like y minus two squared and
then here the r is one so one squared and so there would be the circle right
there and the center would be at seven and then and then add a two right there
so using these widgets right here you can change different values right here and
move the circle around that’s a pretty nice feature right there

00:25
alright so now let’s look at expanded form right here okay so expanded form
all right so now generally speaking this is what a quad quadratic equation looks
like so we’re going to have an x x squared term y squared term a mixed term an x
term a y term and an f term now um you know these this is not just going to
be about circles though ellipses hyperbolas they could all happen right here
so we’re going to simplify this down a little bit to have a circle
because this episode’s only going to talk about circles circles and lines so
we’re going to say a is 1 b is 1 and then the c is 0 right here so what we’re
going to do is we’re going to just look at this is a 1 a 1 and a zero
and so then we still have this um but i’m actually just going to rename
this and call this whatever is in front of the x and a and a b and a c
that way we can talk about the x squared
and the y squared with an a b and c here so we’d like to have this form right

00:26
here right this is standard form this is the expanded form
so you know the standard form is really nice because if you have this form for
the circle then you know immediately what the center is and what the radius is
when you have expanded form then you can’t see that information
by inspection you’d have to go do some manipulation and so you can transform
these circles back and forth into each other or these equations back into each
other there’s only one circle involved but the but you can have multiple
equations for that circle right so if we have the expanded sorry standard
form right here let’s expand it out right so we can square this out right
here we’re going to get an x squared minus 2 x h plus h squared and then we
can also expand this right here we get y squared minus y times k
with a minus and then all times two because there’s two of those terms
and then the k squared and then let’s move the r squared over here and we get

00:27
zero and let’s move the x and y terms out front
and so then we have this term along with this term
as the x’s and y’s and then we have all the constants these are have no numbers
in it right here so in other words i’m trying to take the standard form and
convert it into the expanded form right there and so far we have we have the x
squared good we have the y squared match and what is the a going to be it’s this
number right here in front of the x and what is the b
and then all this is going to be the c so that’s what we have right here this
is the a is right here the b and then the c is everything
without an x or y in it right so there’s all the c right there
so we want to solve this for h we want to solve it for k
and we you know we want to solve in terms of a b and c right because if
we’re given the expanded form if we’re given an a b and c

00:28
i would like to know what is the h and the k and the r
so here’s how we can do that because right now um
you know these are already solved for a b and c what if we change that around
right so if we um solve this um right here for h we’re just simply going
to divide by minus two right here the same thing right here we’ll divide
by minus two and this is c right so we can say here that um [Music] this
you know just switching sides here this will be a minus c now and then move
the r squared over it becomes positive and so then we can take square root of
both sides and now we can come back in with the h the h is minus a over two
and the k is minus b over two and we’re going to square those right so just

00:29
square the h’s and you’re going to get a squared over 4
and square the k and we’re going to get b squared over 4
and then still we have the minus c right here
okay so in case you’re lost right here we’re just switching sides right here
right so this will be r squared equals the h squared plus k squared
and then minus c right so i’m just moving the c over it
becomes negative move the r squared over it becomes positive right there we go
and now i’m just taking square root all right so this is the r now
so in other words if someone gives me the expanded form i can say here’s the a
b and c so i can plug in what is the a and then
i got the h i can plug in what is the b and now i got the k
and i can plug in the a b and c and now i’ll get the r
and just to simplify it out a little bit more think of the c minus c

00:30
as minus four c over four right and so now they’re all under fours
or sorry this all is divided by four divided by 4 and this last term right
here you can think about it being divided by 4
we pull out the 1 over 4 out factor it out and then take the square root of 1
over 4 so one half and then we have the a squared left the
b squared left and the minus 4c left so you can think about r as being this or
this or this whichever way you’d like to think about r
but the point is is that if we’re given expanded form i would like to know what
the h k and r all right so now this is only possible let me move
out of the way here if the square root remember you can only take positive
square roots right so all that right there in east
so this part right here needs to be greater than or equal to this so this
part right here is always positive right so that needs to be greater than or

00:31
equal to the minus 4 4c right there so to make all this happen
all right so let’s look at some examples now
so you know we can look at this right here and rewrite it as x squared plus y
squared and then we’re going to have a minus 4x and then a plus 6y
and then a minus 23 equals zero so this right here is my a
this right here is my b is six and then my c is minus 23.
so once i know my a b and c now we can look up and say what was the
h and what was the k and what was the r because this is expanded form and i’d
like to recover the standard form right so here’s how we found them that h
is minus a over two the k is minus b over two
and the r is well we could use any one of these um

00:32
since we’ll have already found this right here
we can go ahead and use that so that’ll be square root of h squared
plus k squared minus c so let’s find these numbers here okay so that’s a minus a
so a is a minus four right so we have a minus minus four over two
so in other words two and the k here is the minus b which is six so six over two
so in other words minus three and now what about the r
so we have square root of so we have the h squared this is h so four
and then we have plus k squared k is minus three so that’ll be nine
minus four times the c which is minus twenty three

00:33
and so this will tell us how to find the h and the k
and the r so now all we got to do is calculate that up to get the r right there
so we’ll be able to have that x minus h squared plus y minus k squared
equals r squared whatever r we get out for that so that will be
how to write the standard form of the equation of circle
and sketch the graph and we’re going to do all this with python right here to
make it to make it very easy to do lots of examples
so let’s go see how to do that now let’s erase this and
yeah let’s go here and look down here expanded form all right there we go
so here’s our problem right here we’re given the expanded form right here and
we want to sketch the graph of the circle right here so
we’re going to cook up this new function graph circle expanded form

00:34
and we’re given the a b and c we can identify what those are
now we may have to move the equation around and get zero here right so it’s
important you have zero here you have a one in front of the x squared otherwise
you’re not going to have a circle you have a one in front of the y squared and
you have zero over here okay so then a is everything in front of the x and y
everything in front of the y is b and everything without anything in it just a
constant is the c so now we can say exactly what the a b and c are
now we’ll have when we execute this function right here
we’re going to be able to use our formulas that we used a minute
ago we solve for the h we solve for the k and we solve for the y
so this is using the mp square root right here because we’re going to take
the square root of the a squared plus b squared minus 4 times c so these right
here means squared and then we already have a function that
we looked at on the last couple of examples called graph circle so once we

00:35
know the h k and r then we can go graph the circle and then we can go return the
h k and the r so let’s look at this one right here so graph circle expanded form
so we have the minus fours for the a and then we have the b is 6 and then the
c is minus 23 and then right here we can go evaluate that
and so now we can see the center is at 2 3 and the radius is 6.
so the center is 2 sorry 2 minus 3. it’s about right there
and then the radius is 6 6.0 right there all right so
there’s the first example there and so then let’s do a quick another
example here so we have a 1 in front of the x squared we have a 1 in front of
the y squared and we have 0 over here so we can check out what is the a minus

00:36
2 what is the b and then what is the c and so when we shift enter that
there we go now we have the center and now we have the radius right there and
here’s a sketch to the graph of the circle so from this right here we can
say what the expanded form of the circle is right so we have x minus
the h is just a 1 and then y minus the k
so this will be y minus but this already has a minus in it so this will be plus
now and then let’s go ahead and write 1.5 is 3 over 2 if we want
and then the 4.5 squared all right so there there could be the standard form
[Music] equation of your circle depending upon with the decimals if you
want how you wanted to write that out all right so then for our our last
example here we have again need to check everything
works first because we didn’t build any checking into the function right here so

00:37
we could build some checking into this function right here but
we’re just doing that manually so we’re checking is there a 1
in front of the x squared is there a 1 in front of the y squared do we have 0
over here and then what’s the number in front of
the x is it 2 the number in front of the y is minus 3 and then the constant is
minus 63. all right so once we check all that and input all that into our
function then we get the standard form we get a
sketch of the graph of the circle and we get the h and the k and we get
the radius or at least we get an approximation of the radius right there
all right so there we go there’s those three examples there
and now we’re ready uh to end the video so i want to say thank you for watching
and i hope you enjoyed this episode and i look forward to seeing you next time
i’ll talk to you later if you like this video please press this

00:38
button and subscribe to my channel now i want to turn it over to you math can be
difficult because it requires time and energy to become skills i want you to
tell everyone what you do to succeed in your studies either way let us know what