Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
This college algebra course is different than other college
ones, you will be learning all the concepts from an experienced
But in this course, the instructor Ed Protowski will also show you
concepts in Python. This course is for everybody, but especially
science. Hello and welcome to the Algebra with Python course. My
guide on this adventure. So we're going to learn about algebra and
all of your algebra. Because there's so many different things that
You learn these formulas. Hey, anytime you have a formula, you can
So that's what we're going to do. We're going to write some code
That's Python, a Jupyter notebook, essentially in your Google
we'll do is look at how to set that up. We're going to go through
look at the math. We're going to look in the actual lessons. I'll
and we'll look at the concepts, how to do the math on the board.
then how to write the code to do this. And you'll be able to
In fact, I hope you do create your own notebook or two along the
resources that you can use. You can also, you know, once we set it
download the CoLab, the Google CoLab app, and you have access to
your phone. So, you know, you can make your own like, you know,
access to on your phone, you know, solve all kinds of things, you
You know what, you know, building these resources, but also
you go further in math and in writing code and eventually leading
data science, that you really understand these concepts and you
that you're creating. So that's really, that's the idea. That's
going to be a lot like this. I'm going to talk about the math, you
on the board and then we'll flip it and we'll look at how to do
all the resources for you. And then in addition to the core
then what we'll do is I'll have another video or two of extra
So, you know, you know how to write the code, you're building your
and then we'll just work through a bunch of extra problems, you
And it'll be really great. You know, you'll learn algebra, you'll
and you'll have all these skills under your belt that you can use
we're going to build upon these in future courses. So I hope you
to set up Google CoLab in your Google Drive. So in your Google
in folders and, you know, you have a, you'll set up a folder for
you can have all the documents and notebooks and everything there,
and you will have access to all these documents you see, you know,
if we take a look at the little yellow infinity symbol, that's the
And, you know, if you want to create a new Google CoLab, you're in
be, click on new, and it won't be here, and you go to more, and
So Google CoLab. Now, if you don't have it already, if you have
then you go down to connect more apps. And, you know, it's begins
you know, here. But if not, then you can search, you know, and
you just do Co, it comes up. But if you type in CoLab, then it'll
mine's already installed. But if it wasn't, you'd see it there,
button, instead of saying uninstall, it would say install. And
And there we go. Then when you go to new, and then you can go to
and it loads. There you go. So as you see, I like the dark theme
that's just what I picked. You know, you can change that. So this
where you're going to write the code, you know, it's set up to
addition to that, you have the ability to add more code or more
another block of code, you can add more text. And if you click up
And, you know, if you type text, now, if I hit enter, that just
I have to click somewhere else to get out of that. So there you
doing that. Also, if you might have noticed this appear, if you
you can add code or text. And that works anywhere. You see, so you
in between these two. And there we go. And that text actually,
actually use some a few HTML tags to, you know, make new line
And then if you get really fancy, you can use the latex math
formulas. But we'll get to that soon enough. Alright, so you have
you can do, you know, your code, your text. And one of the other
like any document, give it a name. And you'll notice the familiar
Google Docs, you can, there we go. Let's just call this week one
you know, give it a name, you know, you don't want to leave all
might be, you might forget, and it might be hard to find later.
whatever you'd like to put in there, print. Okay. And, you know,
code until you run it. And you can click this run button, or if
notebooks, you can hit shift enter, that'll run it also. And there
here. Notice you can also do a lot of math right there in the
put in math formulas, you see hit enter, it just gives you a new
of math formulas. And remember, the add, subtract, multiply,
this asterisk, two of them. So there you go. So that would be
And you see it'll, it'll do the math right there. If you wanted to
you have to import something. And we'll get to imports as we go
But notice you can, you know, you can have your text, you can
for a lot of simple things. You can just do that right in the
One of the other interesting things you can do is, and if I make
I'll just make that B for a certain reason, then you have a table
Now this has nothing because I don't have any headings or
table of contents looks for. If you click on a new section, then
it as new section and call it good right there. You see it shows
And if you double click, now this B is underneath that section. So
it becomes minimized within that section. And then here, A, if I
then take a look at the section heading. If I double click on it,
would be normally used for a Python comment, but we're, but we're
It would be normally used for a Python comment, but since we're in
just use it to indicate a new section. So I can go up to here,
section. You probably don't need the space, but I like it. And
out of that. So now I have A and I have my new section here. So I
I can put some, I can put some code here and I can, in this code,
arrow over there? I can move it up. And then maybe I'll make B,
make B its own section. I'll click somewhere else. And so I can
and now B is its own section. That kind of didn't matter because I
of it. There we go. Put text in here, click somewhere else, and
So you see, I can have these different sections collapsed, and
of contents, A, new section, B. So if you give them names more
them more than A and B. It becomes useful because you can find
And then you just click to expand each section in whatever else.
section, you can have code, text, you know, and as many of those
goes until you create a new section. So some good useful things
Google CoLab notebooks. You might decide that you might like that
you know, keep them in sections. So that helps. Also, the Google
the Google Drive, it does save automatically, but it doesn't do it
and you do have a save here, and also the normal shortcuts, Ctrl
work. And that way, sometimes, you know, if it goes a while in
it, it might actually prompt you to say that you might need to
to think about. You know, you actually do actually make an effort
CoLab. So we set up our code. We can do math right there in the
sections, table of contents, and all these sections, you know,
expand or collapse them all at once if you want. You know, that's
all the code we're going to work on, you know, you also have down
that looks like, you know, XML or HTML tags, and it's a bunch of
you know, copy and paste, try these right in your Google CoLab
things to explore. And there we have it. You're going to be
You might want to build one for algebra and, you know, just
in which case, definitely make sections because that's going to be
to find what you want. So you could do that. You could make a
for each unit or each week or however you want to organize it. But
these resources that you will have access to. And as well as
you can also download and install the app. So that'll be useful.
That when you first run it, you need to do a few things to go
authentication and such. But, you know, it doesn't take that
All right, so we have this, you're going to be building your stuff
in your Google CoLab and it's going to be exciting. We'll get to a
a lot of interesting things. So let's get into the math next.
So we can't talk about proportions without talking about ratios.
word for a fraction. So this two out of four, I can write that as,
but I could say two fourths. I can call it a fraction, but it's
And then a proportion is two equal ratios. So if I know that these
things I can do with this. And one of the things that works and
multiply. So if these two are equal ratios, then I can cross
I can do two times 10 equals four times five. And that's another
get it out of the proportion mode and I can use this to double
So two times 10, we see 20 equals 20 and then that's true. So, you
works. We can always do this. If these were other numbers, I can
cross multiplying, because if that doesn't work, then that
if one of these numbers is unknown. So if I have three out of six
other ways to solve this, but this is the go-to way because it
when I do my cross multiplying, then I can do this three times
go. Three times four is 12 and then six times X is six X. And then
going to do is going to be dividing by six. So then I get that X
we can jump ahead and say, okay, let's I know that when I multiply
step. It's going to be six X. So the next thing I'm doing is
just put this in one step. So I multiply the diagonal that I can
because I know that the next step and then my answer is X. So we
in writing code. I can see the proportion and I can then just put
for X. And again, that's it's the go-to way it works every time.
for these numbers, cross multiply and then solve for X. One of the
some of the other applications. If I have, let's say I'm
kilometers. So if I have one mile is about 1.6 kilometers, then I
ratio that I know. So as long as I have miles and then kilometers,
out the other. This unknown can be either place. So if I have two
is that? You see, we can make use of this. I know that I'm cross
by one. And then, so there we go. So X would be 3.2. And again,
two times 1.6 dividing by the other number, which in this case,
So then I can solve. So this is what we're going to use. And we're
how to put this into code. And so prompt for these four numbers or
and then figure out the fourth one. So let's take a look at how
at the code. So we're going to see here how much easier it is to
our problems. And just like proportions, we have that cross
time. So I'm going to put just a display here to remind us that
And here's what it looks like. N1, D1 equals N2 over D2. So N for
And if I have a proportion, I would know one of the ratios. So I
And then N2 or D2, one of those I would not know, but I would know
comment here in the code, put a zero in for the unknown value,
these values would be zero. That would just, you know, you
that, that zero is everything out, or if it's in the denominator,
never occur in something that we're really trying to solve. So I
just change these numbers, put in my numbers that I know, and I'll
know. And then I'll put two if statements. So I have if N2 equals
the setup of the if statement in Python. If N2 at the double
I have a colon. And then the indentation afterward is one, two,
some people use a tab, I would hesitate to not use a tab. They
of spaces. So indent four spaces. And then I have the answer is,
multiplying. So you see D2 times N1 divided by D1, that cross
and then we'll print out the answer. And we'll do the same thing
so my if statement, if D2 equals zero, colon, four spaces indent,
notice the cross multiplying. So D2 is what I don't know. So I'd
by N1. And then I'd print out that answer. So there we go. And
equals what over 16. And then if I would run this, and it will
we go. N2 equals eight. Or if I had this, I'll keep this and maybe
Rio, and if we run it, there we go. Really straightforward. We
that we know these we know these formulas, and we can just put
display something to set it up, and cross multiply, solve any
Now that we've worked through the core skills in this unit, let's
And I'm going to work through extra problems using the CoLab
you can apply these resources that you're building and use these
up in a textbook or in day-to-day life. So we're going to go
We're going to work through some extra problems here relating to
working with proportions and ratios. And one of the things that
numbers. And in math, I might write it like this, but then you
And Python, remember, you can even do math in the print statement.
two thirds becomes one plus two thirds, and you see two divided by
sometimes I use parentheses, extra parentheses, but we really
operations. So you could have one plus two thirds, plus three and
plus four divided by five. And, you know, you can change up minus
print statement there and it would output the answer. Now, later
going to also talk about converting that output. If it was a weird
number, but we'll get to that. So you can do this, but even also
if you wanted to, instead of print and you don't need the
there, you can store them as a variable. So if you had something
variable and then use that later on, or any one of these, you
as a variable, because some of these, like two thirds, that will
mixed number, or the one and two thirds that will come out as that
later on, you might want to keep as many of those decimal places
it as a variable will do that for you without you having to write
So really, that's the whole thing. We're trying to build, you
you might use a calculator. Hey, might as well use Google CoLab
formulas in there, store variables and everything. So for all the
work with mixed numbers. Yeah. Print it out, store it as a
work with the rest of the problem. So if this comes out as a
let's take a look at one other thing here. If this comes out, so
one and two thirds. So we know the one, but if I look at the two
you know, 0.6 and it keeps repeating. You know, it'll keep
how would you know that that would be two thirds? Well, one of the
throw in some other variables here. Let's call, let's call this X.
decimals. So if it repeats each, um, each place, then I just need
You see, and that keeps going because if this keeps going and then
if I subtract them 10 X minus one X, so that would be nine X
it, but I am subtracting this bottom row minus the top row because
line up and it would subtract. So multiplying it by 10 moves it
and when I subtract 10 X minus one X is nine X, then that all
how do I get to X divide both sides by nine? So we get six over
we can reduce divided by three is two divided by three is three.
any single digit that repeats is a factor of nine. So if I have,
and actually I might use the same, same formula, but if I have
um, point four and it's a four that keeps repeating. So then 10
and as many fours as you want. So then when we subtract 10 X minus
I subtract this, everything after the decimal subtracts. And so
by nine X equals four over nine. Now, so this works for any number
but this is kind of interesting then, um, how, what if you get a
Because would that be then nine over nine? Yes, maybe. So if I
and so then 10 times that would be nine point and as many nines as
we'll do the same thing. So nine X equals, so you see if this is
this still follows 10 times that. And then when we subtract
it all lines up, it becomes nine X equals nine over nine, which is
So you see some algebra acrobatics. How do I show that point nine,
And these are kind of the things that we want to bring in. Um,
can do, you know, this works out nicely just seeing it on the
different things to convert decimals to fractions, you can see
But yeah, some math acrobatics, this is kind of what we want to be
We want to also sometimes use the code to show different ways to
And when we see it get to a solution in different ways, it kind of
reproves, Hey, this works. This is the true solution.
So these are some of the things that we can do, um, with
you know, some of the other things we'll do, we, you know, we
convert converting, uh, money like.
Yeah. So if I have, you know, let's say, um, you know, one U S
I just looked this up. It's 1.29 Canadian dollars. So if I want to
ratio and proportion as long as you know, I know one of these, so
And then as long as I know one of these, I can figure out the
And in the code, you remember, we just add it, whichever one I
I put a zero there because either way zero over anything is zero.
You know, the zero in the numerator, the answer is zero and zero
undefined. You know, you could look up different, uh, images of
things like going into the abyss and all kinds of fun things like
But yeah, we don't want to divide by zero. So if I know one of
zero, that just really would, we would never arrive at that
that that's why we would put a zero in for the one we want to
have it set up, you know, then I can figure out, oh, okay. Well,
um, how many, I'll put the question mark here since we're not in
okay, if one U S is 1.29 Canadian, then what's one Canadian hour
multiply divide by 1.29 and you'll get that exchange rate. So
to this one, one U S to how many Canadian, we can change it to one
you know, cause very often you find exchange rates and they'll
And maybe you want to find it in the other direction. So these are
use this for. We can also do things like miles to kilometers or,
you know, other unit conversion you want, but you know, if you
is 1.6 kilometers, um, it's that exactly 1.6, you know, there's
another nine meters or something, but okay. And then there we go.
then as long as I have miles and I have kilometers, then it'll
put that in the code. So now that you have these tools, you can
have that ratio of one aspect of it, then you can, you know, plug
figure out the other. So, you know, here, you know, some, some of
of the things we want to do in the extra practice section. You'll
that, you know, we're going to get to the core, um, core skills in
your ongoing, uh, CoLab notebook. So you have some resources and
um, extra practice, extra problem section where we then use some
and let's apply this and let's solve a bunch of extra problems. So
and we will, uh, we'll go on to the next unit.
Here, we're going to look at four different ways to solve for the
And in algebra, we often call this X just because X works nicely,
if I have, I had to put four different situations here, add,
simple numbers because you might be able to do this in your head
explanation is you want to see what you're doing and do the
are equal, both sides of the equal sign, if you do the same thing
So that works. What am I doing? I want to do the opposite to
is do the same thing to both sides of the equal sign. I'm going to
algebra operations here. So if we have X plus three equals five,
the goal is that I get X equals something. So I would like that X
on the left side of the equal sign. So what am I doing? I'm adding
opposite, subtract three, and then I'm going to do the same thing
three is zero. I don't have to write plus zero. Five minus three
So it's like Sherlock Holmes eliminating possibilities, and then
So the next one, if I'm subtracting, I'm going to do the opposite.
something. So X minus two, if I add two, that cancels. That's why
same thing to the other side. So negative two plus two is zero.
Have to write plus zero. And then 10 plus two is 12. There we go,
very similar. Also notice in writing math, most textbooks, you
see a multiplication symbol at some point. Just the fact that
that I'm multiplying. Now we have to remember this in Python
multiplication symbol. But here three X means three times X. So to
so I have to want to divide. And notice I'm going to write that
and then divided by three here. Now here's something else about
by three is one, but I don't have to put one X. You could, but you
you won't see it. One X. Any other number there, I'd have to write
we often don't write that. So then 12 divided by three is four.
Somehow, whatever I teach this, everybody's like, get it, get it,
thing. I'm dividing. So I'm going to do the opposite, which is
I might write it, how can I write multiplied by four? I might even
just saying it's next to that, so that means I'm multiplying.
I'll put in parentheses. So divided by four times four cancels
X. And then here, two times four is eight. So with some simple
add, subtract, multiply, and divide. And the key is no matter what
what else you encounter, how complicated the numbers are, it's the
So we recognize this method, then whatever number comes up, then
this I can do in my head, but supposing I have instead of X plus
7.2 equals 11.1 or something like that. So supposing I have
how could I solve it? Oh, I have an algebra method. What am I
in this case, 7.2 from both sides. And so then I get X equals, and
complicated, I know what I'm doing on the calculator. I'm
and then I know what I'm doing on the calculator. There we go. So
anytime I have a two-step equation. And in the two-step equations,
order of operations in reverse, because the addition is the
like 4X plus 6 equals 22, so two steps, I'm still going to combine
we were talking about. I'm just going to do one than the other.
Like I said, like order of operations in reverse, the addition or
easiest to do first. If I then subtract 6 from both sides, so if I
I have 4X equals 16. And now I get to my second step, divide by 4,
divide by 4, then I get X equals 4. So we have our two-step
are, you're going to get quick enough at this that it's not even
or anything to solve this. But some of these, as they get more
there's other factoring and more elaborate problems, then it would
because I'll show you now how we can just put this in Python,
and it'll output the answer. So let's take a look at the code. So
solve for X in Python because we can just import the Sympy library
math library. You don't have to install anything. You can just
Google Colab works nicely behind the scenes like that. And then
symbols. And from Sympy.solvers, we're going to import solve. So
X as a math symbol and solve for that. And solve is going to be
then I'll define X equals symbols X. And that's defining that X is
I just put this comment here. But then the next thing we have, I
equals X minus two. And this is the function set equal to zero. So
is what we're solving for. And then that's the equation. So then I
statement, print X equals, and Python syntax, then print that
And here's where we see solve eq, the equation, and use X as the
So we're going to solve that X minus two equals zero. And you see
It'll print an array of whatever your answer is. This just had one
But if I had something like X, X squared, X squared minus two, now
answer. Kind of interesting how that'll show up. You see square
make that a decimal. But if we make this something that works out
that, see it'll give me an array of my two answers. X squared
equation. And negative two or positive two, either one works. And
something like two X, I can't just write two X. I have to put, I
that's Python syntax. Two X minus four. And then if we run that,
There we go. Much easier. And all this stays the same. You just
run it, and you can solve anything. Just make sure it's that
Now that we've worked through the core skills in this unit, let's
And I'm going to work through extra problems using the Colab
you can apply these resources that you're building, and use these
You can use these to solve problems that might come up in a
So we're going to go through some more extra problems here. All
bit deeper, looking at different ways we can solve for X here,
code that we were talking about before. So we import Sympy, so we
and then we're still from Sympy, import symbols, and some
to define that symbol X. And this is the simplest thing. We can
just put my equation right here. Here's my equation. And then I
and I'm solving for X. Notice I don't even really need a print
function is the last thing there. And then when we run it, we see
half. And notice the brackets around it, because it's a finite
And if I have something that solves for even, you know, something
plus 1. Now this is setting this equal to zero. So 2X squared plus
solution. We can actually take a look at that. And you see the
and that is I, the imaginary number. So it will give us this.
square root display in a better way, but we'll get to that later.
you know, it gives us two solutions as this finite set of these
you know, minus 1, or I can even make it minus, you know, 4, we'll
But there's still going to be square root solutions. There we go.
will output. But you get this. You can put the equation in there
pretty much anything you can type in there. All right. But let's
fancier. What if we prompt for input? So let's say I want this to
rather than somebody going in and finding that correct line and
we can just prompt for the input here. And notice the function is
display this. Enter equation. And I even have it as zero equals to
equal to zero. You could add another print statement saying make
you know, if that's what you'd like. And this input does come in
are using these symbols, it will be able to interpret that. And
and just putting that into a print statement. There we go. So we
the equation. And maybe I just make it three x minus six. How
good. One solution. Three x minus six, because if x is two, then
But again, if, you know, I have multiple solutions, or maybe if I
maybe I want it to be a little bit fancier. So, again, this solve
so we can do more. All right, we're going to import all the rest
knowing that it's a finite set, I'm going to store that answer as
And then this particular equation, I know this has one solution,
display solution index zero. And that's going to be the first
to be the only solution. So when we run it, there we go. And
it a little bit nicer output, just like having that nice user
having it display zero equals and then waiting for the prompt. So,
do this. And, you know, here's saving this. Okay, that's great.
And what if I don't know how many answers I'll have? So I'm going
so if I enter the solution, now, maybe I'll just put the first one
this one next soon enough. So I'll just take the same solution
And just like we were doing before, I'm going to solve it and
notice my loop here and Python has this great
method of iterating through everything in that list. So for S in
item in that solution set, whether it be one, whether it be
it'll iterate through that. So S is that solution. And then it'll
And each time, I'm just going to print x equals, and then I'm
we make use of the Python shortcuts. There we go. So 2x minus 4,
through and did this. So what if I have something like something
what if I have something like something that has multiple
want to prompt for this. All right. So what if I just plug in
I know is going to have three solutions, because the three
So let's see what this does. Again, loops through, and it will
So we see we're building some of these things behind the scenes
solutions and output it in a nice way. So we see, you know, if
you're going to use, this is the one to do it. Because, you know,
you take out this, this was my demonstration. But there we go. And
So this could be your code. And that will work for anything,
you or you or anybody else using this to enter the enter the
we're building some tools here that we can use to solve. All
Now, some interesting things. We're also this time, we're going to
and we're going to use x, y, but we'll come back to the y. And we
because you can use this for multiple equations, but I just call
two x plus 10. All right. Now, we know that this is set equal to
the go-to way of doing this. But then this simpy syntax, we're
define it. EQ first, comma zero, saying that this is set equal to
for x. That's great. And this solution I just called sol.
And since I have this one, I know that the solution is, you know,
just put salt. You know, that's my finite set. And I want the
actually, these are factored results, but this is actually going
because I can get that answer. X is negative five. All right. Now,
Now, I have to have y there. If I define y as a variable. Now,
this is equal to y. And you see that works. So spelling it out
But now I now I'll solve for x. So that's kind of interesting. And
Python could actually do some of this factoring for you. You know,
algebraically. So now it's solved. Why over two minus five. Pretty
like that. We can rearrange things. And then if I have this, you
around a little bit or whatever. But some different things you can
to zero. Make this equal to zero. But this gives you this other
to y. And then you can do some other things you can solve for it.
as you incorporate this into, you know, some of the notebooks that
around with this and, you know, try some different things. You
some different some different formulas or different equations in a
try this? Like, we could take a look at this and say, all right,
what about if I have two x, then, then if I want to solve it for
So there we go. And if that's included in y, then I still might
this is equal to zero, because that's kind of the default way for
back and solve for x, and it should end up being very similar.
do something very similar, because whether that was, you know,
it's equal to y or with this minus y saying it's equal to zero,
And, you know, we could even just to show you, we can even say
this. There we go, x is y over two, all kinds of different things
rearrange this, you can put that in this setup here. And then, you
set equal to now? And what am I solving for here? And in this
zero for that solution set each time. So these are some cool
the factoring for you. Well, here's some other factoring.
you know, we can divide out common factors. Now, you might see
ten times y, plus four. Now, supposing this is another thing in
You know, I'm not saying that's equal to zero or anything. I just
I don't want to factor it. Look at that. And SymPy also does the
So you see, there was a common factor of two. And that worked.
and let's say this is three, which then doesn't factor at all. So
you know, it will just output that because it's not factorable.
interesting is if I have something else, like x squared, and let's
you may or may not be familiar with that factoring, but I can
I look at that. It'll factor that out. That's the correct
So it will do a lot of really interesting factoring for you. So
we can, you know, just to show you that we can even take it to the
X to the third minus two x squared minus five x plus six. So we
there we go. Look at that. It breaks it down into these factors.
you know, knowing that you can set your factoring, you know, you
factoring, you can make your own factoring calculator here. All
at some of the functions here. So when we have, you know, we have
you've been doing some of this practice with these functions. So I
you know, looking at these and this different input, how we can,
you know, remember you were doing the practicing the one step
the one step addition, one step multiply. There we go. Now, that
is because you can't do string to a fraction. This print, this
we take this input, now other inputs, if it's actually a number or
and you can cast it as a float. So that's a number that could
it's going to be a fraction, this float won't work because that
parse nicely. So then this will give an error. Now, just because
just a display. If I just disobeyed that and put in a number, then
But if I, as soon as they use that divided by, I need that. So
is how do I convert the string input, including fractions to a
functions work. I'm going to use this DEF to define it. And then
I give it the name of the function. I need the open and closed
and this particular one will also have input. So I define this
That's going to be the input and then colon at the end. So once I
then everything under this is indented for spaces. Yep. And I
use indentations. So then I have an if statement and if, and then
is true, colon, and then that's indented for spaces. Okay. So I
and I'm testing to see if this fraction bar is in there. And
in string, cause that's what I called it. That's my input. If it's
Each string has this split function. So you can split it and say,
I'm going to split it. And then that creates two different arrays.
input. So it's going to be two string arrays or two or one array
going to be ND. I call that for numerator denominator. So then ND
everything before that. And ND one is going to be everything after
if somebody put a fraction in there, then ND zero, everything
So I'll cast it as a float, store it as N for the numerator. And
that. So I will cast it as a float, store it as D for denominator.
we had to detect that split that string. And then each of these
them as float numbers. And now these are numbers N and D. And now
N divided by D. So you see, because that slash doesn't work for
like work around it. And now I have ANS as this answer. And then I
this, this function doesn't have a print statement, just returns
comes up. But it just, you know, wherever this function is, it'll
So that's if it has that. And if it doesn't, because I want to be
either way. So anything else, colon, indent, then I won't have a
in string cast as a float. That works. So anything else you put
return ANS. Now, where this comes in, I'll come back to that one,
So here's this function, one step more. And I put this common in
else using this, that it uses this function. So we need to make
All right, so here's, here's the idea to generate, you know, some
random. And then here, I'm going to get random dot Rand int from
a random integer, and I'll store it as variable A. So that's going
including one, but not including 11. So one could show up, 10
So that's, that's the way the random integer works. It includes
And then B, I just wanted to make this two to 24. So given these
notice what we're going to print here. So AX equals B. So we see
times X. And I just want to display this. So I didn't need to
to show the multiplying. All right, so AX equals B. And then you
You want to divide both sides by A. So you know that, and we're
you know, X equals, and whatever your input is, we'll store it as
And then the actual answer at this point is going to be, we know
so the actual answer is going to be B divided by A. So then this
still a string. And that's where we're going to use that in our
string frack. So see, it's going to take that answer, run it
run it through that function, and return right here, that answer.
So that way we can easily compare it because this function will
the double equal sign to compare, and we're going to compare it to
So there we go. So that's the return statement, wherever I don't
print or output anything, it just returns that value right here
And if it's, if it is good, we're going to print correct. If not,
but then print out the answer. So there we go. And now it'll loop
it once, and then, you know, we can create a loop to have as many
practice one-step equations. So there we go, and then test them
And then test them each time. So, you know, we have the simplest
is another very similar one. There we go, import random, display
random integers, and yes, you can go through negative numbers if
All right. And what are we printing out here? X plus A equals B,
you know that to solve for X, subtract A. So we'll take your
But also we're going to calculate exactly B minus A. What is it
we don't need to do anything else. We just say, if A and S equals
And here, see, we can cast the float, cast the input as a float
expecting anything fancy. You see the other one, knowing that I'm
to address all the other things that could come up. And there we
If not, and then we print out the answer. Cool. So some different
one-step addition with negative numbers, just we just did in a
a bunch of things that we can do, just practicing your own ability
more into some other functions later, but, you know, good to see
yeah, here we go. Just some of the things you can do, factor or
that you want to be able to do and, you know, set up, you know,
your own CoLab notebook. So by now, you might have some things
You might have some things to, you know, solve for X and, you
those, you know, convert fraction input to something, you know,
copy these, tweak them, make use of them on your own. And, you
library as well as really understanding the code as you're
your understanding of the math, understanding of the code gets
here. All right, so I think we're ready to go on to the next unit.
decimals and how to convert from one to the other. Well,
could be one out of 10. If I say out of, that means divide. So any
denominator, you can do that on your calculator and it most likely
decimal. There you go. So fractions, decimals, you know, pretty
you know, pretty easy. Calculator, do the division and then, you
what about doing it in the reverse process? So when we look at
one out of 10, I could call it one tenth or 0.1 is what you would
I would still call that one tenth because that first decimal place
be one tenth. Or then if I had one out of a hundred, then there we
So tenths, the second one, the hundredths. So whether I write it
I would still call it one hundredth with the th. Then, you know, I
you know, third decimal is would be thousandths. So, and it would
we have that, you know, tenths, hundredths, thousandths, then that
if we want to convert it back the other way. So if I would, if I
you know, 0.234, so something that I wanted to convert, then I
hundredths, thousandths. That's where it ends. So then I could
And I could reduce that, but that still is the fraction that I'm
thousand. Or if I had something, you know, like 0.4 one place,
four out of ten. And again, I could reduce it or I could leave it
that that's converting my decimal right to a fraction. And when we
we're going to look at how to see here. I'm just looking at this
hundredths, thousandths, et cetera. It could keep going. You could
but I'm looking at these remembering the place values and then
have ten with one followed by three zeros, you know, one decimal
one followed by one zero. And we get into the code, we're going to
in a different way rather than just, well, there's a few ways you
count how many places, or we're going to, you know, one of the
logarithm way, probably the string and just counting it, that's
straightforward. We'll do that one. But there we go. Converting
and then, you know, how do I reduce it? Okay. So we think we have
if I have a repeating decimal? So supposing I have 0.3333 and it
And mathematically, if I was writing this, you put the line over
So I really could just keep it as one, but I want to show you
three. So that keeps repeating. Okay. So we were just talking
places and then put it over that. But if it keeps repeating, where
at a trick how to do this. We want to get to the end of the
repeats once, then if I multiply this, let's, let me call this X
this down a little bit further. This is, that's going to make
X is my 0.3333 repeating. All right. So if that's my value, I only
the decimal place once. And then that cancel out. So if I have 10
And these keep repeating. Now, the reason I do that is because of
everything that repeats now is going to line up. And so if I
what can I do on the left? 10 X minus X is nine X equal sign still
minus zero point, all this that cancels all this, however many
it all cancels and my answer's three. And then one step of
nine. So I get X equals three over nine because nine divided by
three divided by nine. And I could reduce that as one third if I
over nine, you know, that's nice, like bonus math insight. If I
it's that number over nine. That's the fraction. So if I had four
if I had four, if I had, you know, very similar type, type of
something like, uh, if I had zero point four repeating, so then 10
point or four, et cetera. They both keep repeating. Do the same
And when I subtract these, all the repeating decimals cancel. So
four is exactly four. And when I divide both sides by nine, X
So there we go. And, uh, so one more bonus here. If I had nine
we could do the same thing. And you would think 0.999. That's not
in calculus, we can look at limits and how 0.9 repeating. If it
purposes, that is one. But if we did this, it would be nine's
and you get X equals one. So it kind of works out nicely, but this
You know, notice we're not looking at code here. Now we're just
something that repeats, then that's what we need to do. We need to
had something that repeated, um, you know, three, two, two places
that one. And just to give you an idea of a different way, if I
then if I have, uh, so X equals, uh, 0.090909, something like
it's the zero nine that repeats. So I need to multiply it by a
X because that would move the decimal place twice and that makes
So when I do that now, same method, if I subtract these, that's 99
cancels. So then X equals 99, uh, nine over 99 and fine, perfectly
reduce this divided by nine. So that's one out of 11. We'll get
code for that too, but you see, this is, this is one way. If you
maybe you're right the way you write the code, it might seem to
you don't find some way around it, this is the way around it. So
decimal, but now we're going to, what we're going to do is we're
to take any decimal. Just here's the decimal input. How can I find
is and reframe that as a fraction so that given the decimal and
related to that is percents because remember the first is 10th
are the hundredths and that's really what percent means out of a
thing. And then just, I'm always looking at the first two decimal
So, you know, very similar, but just the first two decimal places.
and we'll see how to convert any decimal to a fraction. All right.
convert decimals to fractions with code. And first we'll get some
going to be useful. So if I have 10 two different exponents, let's
exponents. So 10 to the first power, we see this first one, 10 to
10 to the third. We'll see these come up. What happens when we
10 or anything else to the zero exponent, and then we'll take a
or negative two or negative three. So this will just print these
what this does. So we see 10 to the first, second, or third
to the zero is 1. And then the negative exponents are how many
So these are the things we're looking for and we're going to make
our decimals to fractions. So the next thing, we'll take a look at
And we have this formula here, user input, open parentheses, and
will display. And then you'll see then a box, you know, then
going to store that as text as that's the variable. For our
you that you can enter a number and we're going to print it out. I
to remind you it comes in as a string. We can't do any math with
do, any string, I can figure out the length of that string. So
And I just have, again, this comment here, if I tried to do math
error. So let's take a look. So you see, enter a number. And then
like 0.123, I hit enter. You see 0.123, the length of it is four,
these are four characters, the decimal point counts as one
with this. So I, you know, if I wanted to enter a number, now, if
now I can do math to it. And I can cast it as a float or an int
mind, you know, things I might want to do with this, a float can
usually my default cast. But, you know, if you definitely know
we would use that. But we're going to enter a number, cast it as a
the variable number num. Now I can do math to it. I'm going to
There we go. If I enter a number, there we go. And if I have
now I can add. All right, or whatever other math operation you
an int, then you can do math to it. And the float, because it can
operation that there might be a chance of a decimal use float.
together. So converting this input, which will come in as a
and here's what I'm going to print out. Enter a decimal number to
that that's input and that's going to be stored as digits. And we
And we know that that's going to be a string. So to get the number
So I'm going to use this, the length of that input digits, and I'm
first. So notice that happens first. Then I'm going to subtract
that decimal point is going to count when I do the length of that
because I don't want that decimal. So now whatever decimal enter
that's going to be an integer that's going to be the exponent. And
that is still a string. Now I'm going to cast that exactly as a
So now I know how many decimal places it took to make that and the
So let's talk about our fraction. My numerator is going to be n
10 to that exponent. So in my previous example, point one, two,
you know, that was four, the length of that was four, so minus
my exponent. And then when I multiply it by that exponent, it
know it's going to be a whole number, I will cast it as an
numerator. And then the denominator is going to be 10 times that
what we were doing before we were doing the code. You know, how
and then, you know, my numerator is that times 10 to that many
denominator is just 10 to that exponent. So three decimal places
and then the numerator denominator would be 10 to the third, and
Now, that's numerator and denominator for any fraction. Percent is
places. So whatever n is, I'm going to multiply it by 100, because
That decimal, move it over tw- move decimal place twice, which is
see the output, the decimal. There we go. We just repeat the
and I'm just going to print this out to show you it's numerator
percent, and then I'll print out the percent symbol. There we go.
something else, but here I'm putting it in quotes. It'll just be
to enter a decimal number to convert, and there we go. Point, uh,
The decimal, point, one, two, five, and then the fraction is 125
and the percent's 12.5. And we can run this again and do this for
Um, you know, point two, enter. So it's point two, two out of 10,
And there we go. The same things we were doing, and this is what
look at throughout this course. You know, the steps that we're
this down, and we're pretty much doing the same steps, but then
code, then, you know, you have a formula that you can reuse. Okay,
script here, and I'll be able to convert any decimal to a
Now that we've worked through the core skills in this unit, let's
and I'm going to work through extra problems using the Colab
apply these resources that you're building, and use these to solve
have, problems that might come up in a textbook or in day-to-day
some more extra problems here. So now I want to show you how to
You know, this is what we're talking about here. You're making
the things that I'm showing you, and you'll have access to all
but you're going to put together yours. So you're going to click
the Google Colab, so go over to Google Colaboratory, click on it,
so actually I will call it that. I'm going to put the underscore,
your calculator, and you just hit enter or click somewhere else,
you can do to put together your calculator based on things that
and then things that we do further on in the class, then you can
go to, let's say, the week one notebook where you solve for
and here's some things you can do. So if you click on this text
let's copy that first. So you click on that text and go all the
This looks like copy, but it actually doesn't do what you're
Click on the three dots, copy that cell, and when you go back to
I'm just going to click in the open space here and paste it, Ctrl
it's kind of cool. So, you know, Ctrl V for the Windows, Command V
either one, and then we can go back. That's your proportion set up
over all the way over the three dots, copy cell, and your
So you can have this, you know, we don't need this. If you have an
the trash can over there. So there we go. Now you have your text
and then it really is then self-explanatory. You know, you see the
N2, D2, and even the comment there, put the zero in for the
each of these. Then if we look at week two, now we were doing a
and maybe you don't need to do the simplest one. Maybe you like
that. Doing more with the solution, how we split it up. Now, I
might be the one that I copy as one of them. And what you can do
because notice this one, I personally like this one. It prompts
that it's something equal to zero. You know, there we go. We
this also prints out multiple solutions if you have them. So this
And when you go back into yours, now if I just paste this, that's
And notice it didn't paste where I wanted it to be. So watch what
in here and use these arrows. I'm going to move it down, and
Now, we wanted some text in there. So right above it, you hover
solve for X. Maybe I'll just add that text there. So there's more
That's nice. Now, this solve in other ways, that was pretty good.
factoring. So you could include something like this, solve in
you know, simpy.factor. Now, I might include this because you'll
the one of the other ones. So if we copy this, and this is just
do this. And this is just factor when there's, you know, nothing
we'll copy this cell, and paste this down here. Now, maybe I'm
factor. And down here, then I will paste it. Didn't show up where
arrow, move it down. So, you know, there we go. We have set
But we can even make this, you know, equation to factor. And see,
want. There we go. And then, you know, you can factor things. So
the next week. Now, notice to put it all together, because when we
of these leading up to converting a decimal to a fraction. So this
You're prompting the person to enter in this, and then we're going
decimal, the fraction, the percent. So that's nice. Maybe we copy
back to. So then we go down to here. Maybe I'll paste that here.
some text ahead of it. Decimal to fraction. So you see now you're
here. And we don't need that output right now. Now, we have one
for a variable. And notice it's when I paste this, I might put it
remember we did this, then you have the left side, which could be
of the equation, which could be anything. You know, this would be
you would need to change here. Change the variable you want to
your basic common variables that you would use, but you know, you
if you want, but you might not need to change that line. And then
even if it is something that you can just, you know, solve for a
It doesn't come down to an exact number here. So that might be a
example in here. You know, copy this. Now, we might put this in
factor solve for x, and factor solve for a variable. Maybe we put
And notice you can just click and add code. I'll click right in
And this will be pretty much right where I want it to be. Then I
add some text, solve for a variable.
Now, these are just some examples here of how you could put this
So that then you have your resource here, proportion. There we go.
solve for a variable, convert decimal to fraction to percent. And
you could add more into this here. Now, supposing you want you you
then you add all this, that's this is a lot of scrolling. So one
is now I'm going to start with proportion. I like so right around
there's multiple ways to do this. You could insert, you go up top,
a section header cell. So I'll do it one way this way. I'll do
And actually, I want that above. So I noticed this, when you
some of this. These text boxes accept HTML, look at that the br to
and they accept latex, which is how to format various things
all kinds of things. So in this new section, and you see, because
that's not a comment in Python, it's the new section. And I might
Okay, so now, you see, it takes that and all these cells become a
I don't want that. But what I want to do is, if this next one, I
this section, and I don't need another one, I think that'll be the
There we go. So I'm just going to put this here. Now that's a new
So we see proportions now just has the two cells, the text about
And solve for x has just one cell because that section said it
There we go factor. And maybe you want to say something more than
but you can make this a section heading. Solve for a variable.
this together. So you see solve for a variable.
Convert decimal to fraction. You know, that probably I didn't need
solve for a variable. All the rest was explained in the comments.
And convert decimal to fraction.
So now this just has the one cell. And the advantage of doing this
you see these lines. Now we have the table of contents here.
There we go. And I could change, you know, that's long enough. I
two lines, but that fits so that it's a longer title, but that's
table of contents that you can actually go through. And you see
x. You know, different things. And in the view, you could change
You don't have to, but you could. And then you see you have all
So these are some things you can do in putting together your
Putting together your Google CoLab notebook. You know, I want this
that you're building. So then you're learning how to do all this,
your resources here that you can then refer to. Oh, what do I need
Enter what I need to enter and solve it. You know, you're
So that's what I want you to do for this unit, is take a look at
and put it together in your own notebook. Some of the things we'll
and we'll, you know, make some of these into functions that you
But this would be a good place. Put together your notebook of
but you know, you can tweak it to the way you like it. All right.
So what does it mean to be a function? A function means it in math
some input and then doing something to it. And actually there are
don't have to take input, but in math we will. So like we were
being X, the output will be Y. So each function we want to take X
to say that the output is Y. And here we're dealing with all
and then outputting Y. So you see we have like solving for X we
have a second variable and we still want the idea that just like
in science and in research, we can call X the independent variable
first. And then Y is the dependent variable because it depends on
want to solve this or do anything to it, then I'm going to plug in
and I can pick any value. I might start with zero. So I'm going to
is zero. And then what happens when I plug that in? So that'd be Y
And you see I'll just put in zero in parentheses where I plug in
it highlights that that's what I just plugged in. And also the
I'm still multiplying. So when we do this two times zero zero plus
three and my output is Y. And if you remember then that's an XY
Y is three and I'd be able to plot that point and I can keep
what other numbers can I plug in? I'm even just going to keep
X equals one. Plug in one. Two times one is two plus three is
And then we'll plug that in and I can plug in as many or as few. I
integers. I tend to do that so you can see the numbers a little
But you know you don't have to worry about doing any other
But if I have this I can put in whatever numbers I want as many or
numbers in there and we can plot these on the graph which we'll
But this is the essence of a function that X comes before Y. I
output the Y value. So another function notation that a lot of
another variable Y and this connects a lot with the way the code's
F of X and F for function. So two X plus three. So if you see
Y equals two X plus three or F of X equals two X plus three. This
what we read F of X, F for function. We solve it the same and this
your computer science. So if I have the output called F of X, one
into writing the code is that in algebra we tend to just say F for
or other code you can actually give your function a name and it
function. It can be add, divide, calculate the area, something
long as there's no spaces. So if we have this and then sometimes
into two I could write in F of two. And so again the usefulness of
what what am I already defining as my input and then I know what
two times two plus three. Two times two is four plus three is
I know that answer and when I see that X is two, Y is seven. And
relates to the code and how we can write even a little bit more
and how we can define the input there. Then we'll look at graphing
look at the code. So with the code and functions we can do very
by hand writing out the math. Here I'm just going to define one X
the function that Y value. Y equals four times X plus three. And
make sure we put the times. So I'm just going to plug in that Y X
in for this X value. So it's four times five plus three and then
my solution X comma Y. So we see that and before I print that out.
but I can loop this. So I'm going to print out this line here
tab Y. So that's defining my columns here X and Y. And then what
all those values. So for X in range 11 so X is going to go 0
take that same function and each time then I'm going to plug in
I'm going to print out the X Y values. And in this case again I'm
So this is the essence of what we're doing with a function. Each
solve for Y and then I have an X Y value and this is going to
So when I run this we'll see it'll come out first of all we'll
you see five twenty three five comma twenty three that first
Y and all of our X Y values if X is zero Y is three if X is one Y
five twenty three that shows up on the list too. So that's
lot of other functions beyond math you can do things with and we
of Python function definition for our math. Here we can on this
space and Python I can name my function anything but I'm going to
F of X and then here I have a colon. So this is going to define
is indented four spaces and I have Y equals my four times X plus
and what am I going to do then I'll return the Y value. So
Y value. So you see this in use if I print here if I print five so
my X value comma and then I'm going to call this function right
take that and run it through there we go. Same type of thing same
define this and when we run this it's just going to print that 523
loop I could just take the same loop here and I'm going to copy
loop if I wanted to and in this case I'm going to print because I
defined I don't need this and I could really just put put that
I could just have right here since I defined that function X F of
and I don't have my headings here but I think we can use our
one value but then in the loop just went through and looped so
illustrate a function in code and you know what we can do with
almost limitless you know you can have a function do anything and
more complex than this you know give it a word but I wanted to
classic math notation and functions in Python whether I actually
that still works as a function or whether I define it and next
so now when we talk about graphing functions we'll use this
and I'll use the x and y notation so we have our input and output
values and what y values match up so if you ever come across
you can see that if I plug in both of these x and y that should
have a few of our points here and then now we're going to see how
plane our x y coordinate plane it's Cartesian because Rene
zero zero at the center and how much I count for x positive to the
it comes first like x comes first in the alphabet then my y value
and my coordinate pair would be my x y so this zero three would
zero so I'm not going left or right at all up to three plot the
write this but I'll show you so then that would be the point zero
so I would go over one up five plot the point and then that's one
now I just plotted three points but I'll tell you if you really
decimals or other numbers that are in between you could bet that
one point something two point something they would all end up
there's no x value that can't go into this well whatever weird
number anything so all the numbers would be on this line so with
going to call it linear and we'll get into other types of
points and then we want to look at these patterns what type of
so what we're going to do now is look at in the python code how to
to make a basic blank graph we're going to import this library
we're going to we can import this as plt so I can reference this
out and here's what we're going to do the first line is these are
fig for the figure axe for the axis so these two variables and
and then that sets this up and we'll do plt.show the base there
show and then that gives a basic graph these are all the defaults
and you know we have this set up so we're going to build upon that
here notice that was all just the first quadrant everything's
positive and even only one goes up to one so again import matplot
first lines but now let's take a look at these dimensions now I
and I'm going to set this axis all right and it gives you the
going to show a better way in a second but you can do this on one
when we show it I want it to go from negative 10 we see across the
up to 10 zero in the middle and on the y-axis negative 10 up to 10
great but I have no lines I have no axis and you know not the
here's a better way to set the dimensions is I'll define them
as variables x min x max y min y max and that way all right I want
and I can set them here easy to see it and change it if I want to
really what I'm doing when I set the axis size x min x max y min y
that it's taking and it becomes a lot clearer when we set it up
I can set this and then if I wanted to I say oh for this one this
so maybe I want that y maximum to be 20 instead of 10 and then
size of this still looks the same but it adjusted accordingly and
and on my x-axis negative 10 to 10
and so let's display axis lines here if I have my dimensions
well that's the one we already did here the window size but I'm
this line here I have x min x max as my array of x values see
array of x values and then my array of y values and the default is
just plot two x values and two y values it'll draw the line from x
in quotes makes it blue so we're going to do the same thing with
are going to be 0 at 0 y min 0 y max and then it'll get make that
just because I like blue and there we go so now we have this that
so from everything we do now we have an axis we have a point of
so everything that we plot is going to you know start with this
set all this up we might not even need to change any of this and
with an x y-axis all right so how do we plot one point so we see
and I made it blue b in quotes so how do I plot a point well I
I have an array of one value which is five for the x value one
and then the r makes it red and the zero makes it a circle
other options you can do you can do a dash you can do different
to make this a red circle and that's how we make make that circle
here if I have these two and so when I run this it'll still plot
do five four and then that's going to be a red dot all right so if
now connecting with what we were doing with the functions here I'm
and here in rain in my range I'm going to have the range from 10
from this value my y value y equals 0.5 x plus one and in this
going to do plot plt dot plot and I'm going to plot that x y value
I'm going to plot these x y values and again that's the essence of
these different values and when I plot all these points I'm going
that this all lines up and I'll tell you if I plotted points that
x values there would be they would also line up that's why it's a
of it's going to be a straight line and then every point on this
this function it's going to work so my loop to graph a function
to do the function and the table so like we were doing before I'm
graph that I have I'm going to print the x tab y for the heading
I'll use the same function here I'm going to plot the point and
and all these it it actually won't plot all the it'll kind of save
them all it's really just going to add them all to the table and
really doesn't show the graph until the last thing outside the
when you have graphs I think Python just likes to have that
first and then show the graph so then we have this and we have our
put one number in the range it'll do zero to that number but I can
or I could even just go back to those original values that I
x min x max you see and then but as you know you can put any two
do the range between there and you see it just abruptly starts
I could change that to make this x min and I can make this x max
last point so I'll do x max plus one and I can have that range and
of values and it'll graph the full dimensions so there we go we
I have whatever math function I have plug in different values and
numerical output see the graphing output and now we see the
now that we've worked through the core skills in this unit let's
problems and I'm going to work through extra problems using the
see how you can apply these resources that you're building and use
might come up in a textbook or in day-to-day life so we're going
extra problems here so let's talk about more ways to graph and
because we want to be able to display our data our functions so we
can loop through inputs you know I can define my graph and we
y min and max and we talked about how we can loop through I get x
going to plug this in and plot that value and that's the idea of
x value in this range plug it in for y plug it in here get y and I
as a red dot after doing all that then we show the graph but what
a loop for our input what if we could use an array and we'll
but we have this numpy array and it's not that long of a word but
convention that we import it as np and so you'll see a lot of
np dot this or that so that's what we're going to do and again
so given this numpy array here's what we're going to do then given
how many points I want in my array and in this case it's going to
min I feel like that's probably enough for our purposes but that
10 or whatever you want and then we see so then we want to make as
these values as we can that way if that changes if I change my
accordingly and I don't have to go through and find all these
range times two so that's two points through that you'll see that
just fine but you can always increase that so now they have any
of x values and since I really am only using this once I'm going
my array of x values and so numpy we have np dot linspace so we
going to set up our array you know space for linear graphing so it
I start where do I end and how many points do I have so we see we
and then I get my x value so this saves us the time of having to
for us here's all the graphs and we're going to talk about how to
in a minute so now I'll just I like to define my x value up there
in the range so I have my y value and for our purposes here we'll
it y equals but you can graph multiple things on the same axis and
whatever you'd like so I just define this relatively simple linear
when I plot I'll plot x and y and if you remember before we were
in this case with only one element but here you see I define my x
and therefore y becomes an array of y values so I can just
they each do represent an array in this case then I decided to
quotes so there we go and when we graph this then we can see I
about like that would be 2x plus 1 with the red line all right so
things we can customize here now yes r g b work well you know I
line r g for green and if I want it to be a black line then I will
those all work as you know simplified ways to define the color of
put anything python will actually assign a color to each line and
you plot a few lines they each get a different color but if you
want it specifically to be this line for this color you can define
those major colors you can actually just write in colors then you
abbreviation for pink but if I want my line to be pink I can write
every color that will be acceptable here but it's going to be a
a line of a particular color type it in try it and there we go so
to define the color of line because remember this plot when this
it's a line so if I want it to be a point then I would have to
array but as each an array of one value and then the the letter
circle or the carrot for a triangle or something like that so or a
if we just wanted to be a point we'll see that in a second here so
and our line but we're you know we're not done customizing it
a look at these tick marks you know zero and then every 2.5 maybe
we'll change some of these things and maybe you know this seems
the grid lines so here's some other things we can do all right I'm
certainly matplotlibrary but I'm also doing numpy because we use
graphing and same thing I'll define you know the window up here
window so for now I'll keep this you know the same axis I just
now notice when we do up here figure and axis so the labels would
axe dot set x label axe dot set y label axe dot set title there we
graph and I didn't mean that some graph like whatever I meant more
charlotte's web or some graph so anyway so we have these and I
later and I have a few other things here so I still have one y
now notice this I'm going to define this as a label you know it
rather than a color but notice no color I can also do a color but
what color python assigns to us and then I decided to plot a point
zero red or that's actually oh the lower case o so it's going to
this one's going to have a label too and I'm going to plot
then notice I can define the y value up here and then say y right
in here directly either way whichever you feel like doing I don't
options here and again we have this label also so let's just take
late set x label y label and the title and then we'll see these
so there we go and you know we get nice orange a different shade
and I define that as a red dot so there we go but what if all
what if I want the axis to show the grid it looks kind of plain
when I comment that out and this one notice true is a capital T
it will actually show the grid lines and you see it does line up
there every 2.5 but there we go so if we want to see the grid
and we have this and now we have our x you know our labels x
you could actually put the graph and in one of the later units
to even automatically if I wanted to graph one line and have the
but you know you could always just type that in you know instead
just type that in as a string you know the equation of the line
again and in this case let's say the 2.5 in each direction is not
have x dot and we're going to set x ticks and set y ticks so
so it's a different sort of array I'm going to do num mp dot
very similar to the way we did x values I get my minimum my
I want to tick mark every two numbers so that's what we're going
you see again basing it off of those original variables if the
will update automatically so there we go so let's just take a look
tick marks and we see then now every two and maybe that's a little
and we see these now if I wanted it every one then I'm going to
this is just for the tick marks along the side but up here when we
going to just follow whatever tick marks we've assigned so now we
and now we get this sort of graph where I definitely can count the
let's take a look at the slope of each line let's see these and
so that way it doesn't get in the way of anything that's in the
all right there we go so we can keep this that's that's pretty
we have all these labels but we didn't see them anywhere so if you
add this other plt dot legend here we go and we can see these
each of these labels we can have you know this line we labeled
just wrote the word point but you could put anything and the other
some more steeper line so we could always do this and in the same
assigns it you'll see the matching you know which line are we
referencing so some good things that we can do with these we can
can change how often they come up we can have the grid or not we
all right and I encourage you just to get in and you know tinker
all some of the different ways you can you know match up different
different things and we will get into even more graphing but
systems of equations and some other more complex graphs so then
you know go a little bit deeper try a few more things with the
will get you to be able to display any function you have and you
way that you say yeah this is exactly how I wanted it to look
all right so yeah get in there and tinker with this and see see
so let's talk about slope how can I describe this line that's on
how it goes up and over so that's what slope is picturing these
that they go on some sort of angle but we're going to describe
much am I going up and how much am I going over up and over up and
two points and if I have the graph that I'm looking at that's
that's great I can just count you know looking at two nice points
makes it easier to count so I can say from this point to this
three and then over one so up three over one well then my slope is
you know from that to the next point I can go up three over one
plot a point etc and it would be the same slope anywhere on the
equation it's a perfectly straight line so that's great I can
you know just have things like this but if I have the points that
up that's the change in y because y tells me if I'm going up or
up I just counted three but I could also subtract taking a look at
or then how much am I going over and it's always over to the right
so from one then to two two minus one how much am I going over so
in this case it's positive because left to right it's going up if
then my second y value would be less and when I subtract then it'd
always going to the right but y would be positive if it's going up
and so if I had these and I can count but looking at this I know I
formula look like well I can write out the formula here slope m
m for slope because it's how much we move on the graph so somebody
caught on so we're gonna use m for slope how much we move on the
much am I going up so that's the change in y and I can subtract
a little subscripts you know y2 y1 and that indicates my second y
then the change in x would be very similar x2 minus x1 and again
x value minus the first one okay so now that I have this formula
and see so we'd have four minus one or minus one I'm subtracting
two minus one subtracting the x values and what do I get four
two minus one is one and three over one any whole number over one
a whole number I don't have to write over one so I can just write
see anytime you see a slope that just is a whole number it's that
so we have counting if I have the graph subtracting if I just have
you know I'm using that formula so this is great it's the same
slope for a linear equation so let's take a look at how we can
you to get into the mindset that anytime we have a formula you can
and you know there we go input the numbers and output in this case
look at the code and we'll see how we can do this now this part is
want to show you that you can connect any formula if you know here
y1 x2 y2 and put that into the slope formula slope equals y2 minus
and really then this is a useful formula and others you can just
and run it through the formula here we're just going to output the
there we go all you need is the two points next we're going to
but then let's take a look at how that comes together on the graph
all right so we've already figured out that the slope is three in
we have this two points and we want to figure out the equation of
linear and I have these two points that we figured out that the
to the next we went up three and over one or I just subtract four
and then four minus one is three two minus one is one so three
slope is three and we want the full equation of of this line now
imagine here that it would cross the y-axis somewhere and that's
the intercept is where does it cross so we have a nice formula
intercept form is y equals mx plus b now we call the slope m
one point to the next and we'll call the other one b because
so many things happen in this first quadrant where everything's
we begin on the y-axis and then move in that direction of course
different directions but so I have this y equals mx plus b now
x y comes from any of these x y points so I'll pick one of these
y-intercept it works out that way so if we take a look at this I'm
points how about I take this this first one here because it's one
easy to calculate it works for either one so when I plug in this
and then the slope which we just figured out was three and then
put that in parentheses so notice mx you know in my math notation
multiplying just because they're next to each other so I'll do the
you know m and then plug in for x and now b I don't know so that's
that I know one point so that's four things that I know one point
two things I know three of them I can figure out the fourth one
equals three plus b and remember our one step equation subtract
negative two equals b so now that I have this I figured out that
that b is negative two then I put it together leaving x y open
line will work in this equation and my final equation is y equals
we go we've figured out this slope intercept and so now I know
so that coordinate point would be zero negative two and we can see
it shows up like this because when x is zero whatever I plug in as
going to zero out so three x three times zero it zeroes out and
and then I have minus two so we see that that works out so this is
and we can when we see this now if we know the slope we can
intercept if I had this line I could generate that equation we're
straight line but if I had this but if I had this line I could
it begin at negative two oh I know that that's b and then I can
one so then I know that the slope is three and I can go the other
didn't have the graph I could say oh I'm going to begin at
point and then the slope is three I would go up three over one
plot a point and if I was doing this by hand you know paper and
points and get out the roar and connect the dots but what we're
going to do here is take a look at how we can write the code to
would need is two points and I'm going to do more than calculate
the full equation so we're going to look at how to take two points
equation so now we're going to put it all together and develop the
going to define our x1 y1 x2 y2 from two different points and
which now we're going to call m that's been the go-to variable for
moves so same formula but now it's going to be m equals y2 minus
then I'm going to define the y intercept which is b and that's
things happen in the first quadrant where everything's positive so
axis somewhere where x is zero so we'll connect this with the
know how if how do I if if I know a point and an x so an x y value
I solve for b a couple steps of algebra so then b is you know y1
b solve print out the equation so this will just print out the
that it'll display nice y equals three x plus four and I still it
as a float variable so three point zero it's not worth trying to
this is going to work for any number and then that way does not
to to make this work so there we go knowing these calculate the
then put it all together in the formula so then let's graph it
y points and I just kept these same points here so develop the
because we want to print it out so that we're going to print out
to go back to the graph that we were doing before define our x min
this line I can graph I can find two other points so I'm going to
in the first line y3 I'm going to take the x minimum and I'm going
plus b that's going to be my y value and then I'm going to take
that's going to be my other y value so now I have these other two
same as we were doing before and we have now I'm going to plot
and my x values are going to be x min x max and my y values will
going to plot this as a red line so if I part if I put an o in
separate red points but just r makes it a red line and now when we
there we go we calculate the equation and we graph the line good
I can have any other two points there we go there we go two three
we know this actually some of this would break but it might still
not a function there so there we go six and I'll make this one
eight just to show that we can just change these and all the rest
solve for m and b get our equation plot them here and when I run
so 1.25 x plus 0.5 and we see then it must cross the y-axis at 0.5
up 1.25 over 1 there we go all right so now we can graph and
do whatever you want with the two points you find
now that we've worked through the core skills in this unit let's
and I'm going to work through extra problems using the CoLab
you can apply these resources that you're building and use these
might come up in a textbook or in day-to-day life so we're going
extra problems here so we're looking at how we can apply some of
to real life situations and use this information to predict things
and real life or things that show up in a textbook that hopefully
so let's take a look at some examples here and we'll work through
a town's population increased at a constant rate in 2010 the
population had increased to 76,000 if this trend continues predict
want to notice that these are two x y coordinates time and
going to be on the x-axis almost all the time so if we look at
or 2012 76,000 so when we when we do this we have I could make
hey this is the beginning of this situation I'll call it time zero
these are nice even thousand so I just might call it 55 so time
is when we have the next year so that's two years later so two and
that we're recognizing these as you know x y coordinates that we
going to use that we're going to predict in 2016 so let's take a
hopefully you've already been putting together some things that
you know your co-lab notebooks so that you would already have this
know graph you've already done the imports this is the only thing
this for the two points and then we're going to calculate the
so x1 0 y1 is 55 x2 I would want that to be 2 and y2 is 76 so you
0 55 2012 76 000 and these this would then be the only thing you
because all the rest of this you'd have this you know already set
you know we're going to calculate the slope we're going to use
now we happen to know because we have x1 is 0 so we know that the
but that's okay we're going to print out the equation and then our
normally have this set at you know negative x min negative 10 x
maximum 10 so this is the other thing that we would change because
an x minimum of negative 10 so in time that would be 10 years ago
to worry about going in the past and making that negative 10 so
I'll just keep it at zero and we can you know look at it from
that's probably just as good you know we're looking at the most
and y minimum I'll also make that zero actually because y is
than zero would just be weird negative population they're not
anything all right or y maximum and I picked 150 because we
going to 76 and we're predicting a few years in the future so I
didn't seem like enough so we could always change these so all we
notice all the other things for the line that we're going to graph
printing out this line I'm still just using these x min and max
this line and we're just doing the line that way there's other
for how we're going to display this line this this works for
and we still keep our basic setup now here's where we're also add
have these and you could also comment these out and then use them
commented out about setting the x ticks and the y ticks we'll see
to change that and you might have the default x label as x values
can change these here time and population and I like I like seeing
situation so I'm going to put that in as true so we have these
could have your setup and have these all commented out that all
as needed and then there we go we're going to plot this linear
like when we run it so we figured out the equation so it's going
so we see this trend and we see it starts at 55 increasing about
so year two we see yeah I'll estimate that as 76 year four and
now this might not be exactly 120 we could we could plug that in
the equation you know what what is the value at six years but also
I didn't worry about changing the tick marks because the default
actually ends up being pretty good so there we go as a good enough
for you know population estimates you know you know the fact that
or something like that you know our rough estimate is going to be
and then we have our dice labels time and population the grid
we want to do this we can you know we can set up this equation and
answer all these questions there we go we see the trend and we can
that's about 120,000 all right now here's another one the number
cold dropped steadily by 50 each year since 2004 until 2010 okay
here so dropped steadily then we're talking about a subtraction
since 2004 is the first not first year we we mentioned this now
life yes they wouldn't be perfectly linear but a lot of times that
enough approximation and that's that's the idea for some of these
so now we have in 2004 875 people were inflicted and notice even
definitely see there's your xy value year and then afflicted and
so one of the things that we can do here well this is find the
things we can do is I can make 2004 times zero and then that's
so if we take a look at this 2004
I'll make that time zero and then this one I'm going to make 875
875 all right so now if it drops steadily by 50 each year all we
more point if this is linear so we can just do the subtract you
here then if we have year one then it drops 50 so then that's
that's all we need two points and we'll be able to do everything
the intercept and display the equation I might even well now the
anything so you know number of people afflicted you know okay how
of cases of the flu there we go so there we go time cases and you
shift enter or click this and we see this trend negative 50 was
negative 50 x plus 875 and a lot of times you would see this
and then subtract but that's okay now also this notice that you
to show anything why because it started 875 and you see 140
x minimum and maximum that's fine y minimum that's fine but y
maybe I'll call it like 900 so now we can see
the graph and sometimes you know you graph it and you say well why
look and see oh it's the window out of bounds here so there's 875
so there we go and we can use this to predict you know in in any
to get the exact amount we can you know for any any year we can
and then solve so that works and remember that even works within a
you know so the interesting thing is this plot dot show
um that needs to be last so if I do another print statement I
you know the same place where I print this I could print so
print this I could print so what if the question was how many you
the flu we might say oh look at this two years later you know we
subtraction so let's say like five years and you see given our
trend we can estimate it but we don't know exactly you know it's
can say oh about in about five five years how many people were
I want that exact number so I can go back to this and then x is
is in the print statement you can actually just do do the math and
print statement if you want but we can just do our math here
so we see you know our negative 50 times five plus 875 and that
be the value what would be the number of people afflicted after
have a more elaborate print statement to say something but since
question is now that that's 625 that that means something to me
that that might be you know could I estimate it exactly oh that's
can plug in the number and get it so we see you know some
we can answer some questions do some math for you know some
to this now all right all right linear function so here's another
afflicted so we want to know looking at this graph when is the y
be zero now rather than now one of the things you could expand the
until it gets to zero we'll come back and do that in a second but
is if you already also have your setup to solve an equation so you
this was the whole setup to solve an equation and print the
to do here we keep this equation variable the only thing we need
this case i'll put it here h 75 minus 50 x and remember it's
so that's by default set equal to zero so when we run it so the
that gave us a fraction but there you go so that's 17.5 so 17.5
so yeah now again fictional numbers i feel like you know in 17.5
going to be that nobody has the flu or something like that but we
and we can change the x maximum to 18 and then we can see this
according to this trend you know time zero and that would be you
case according to these numbers who knows it may in some
or 18 years that would be like 2022 and yeah i feel like that
nobody afflicted with the common cold all right but anyway you see
the these are realistic enough that we can use these to take a
and this is what we want to use this math for predicting trends
have so here's another one where they even give you the partial
all right so this is showing profit so this figure one is showing
in a given year x and they also do x represents years since 1980
zero is 1980 so then 20 so so 20 that would be 2000 and 30 that'd
we go now given these we want to find the linear function all
want to look at these i just want to find two nice points that i
estimating the points so i like this first one at year five it was
because it says y in thousands so therefore 10 000 would be 10
thousands then 10 000 would be 10 million in which case they could
but that's okay and then we have so five i'm going to shift it to
y value 10 so five ten and then let's find another nice point i
and we can plug in in these so i don't have that zero value and
at some point so five years then we're talking 10 million and then
then we were talking two four
okay so there we go we have that point five years 10 million 25
since we already see this graph since i made them 10 i really
a look at this and say oh yeah 12 is probably fine as far as a y
this to 30 or you know we can take it further so when i go to
going to be enough maybe i'll just make it a nice round 50 y
would the scale would be so much it would this would just be in
so maybe we'll just call that 15 or something like that all right
like the space in there we could just delete this and we have i'm
the equation so when we run it so here's our equation negative
and we see this downward trend over time and here's another one
change these tick marks maybe i could change this to the x ticks
is two enough yeah yeah maybe and then i can change the y ticks is
and we'll run it so we see we get much many more lines all right
we see we get much many more lines all right and with that we see
now just because these end up being rectangles more i might change
i just like that better and you know in doing this you can you
go there we go so with this then we can really see the trend
this downward trend down 0.3 so it should go you know over 10 it
here we go and then 38 years later then they would have no profit
that we're saying there we go so whatever this company is this is
and then and then there we go um
um 38 years later then they would have no more profit so who knows
you know our fictional company is you know something would have to
the prediction lines you know the the the simplest prediction is
line whatever trend would continue in a straight line unless
uh normal business normal day-to-day life things do change and
perfectly straight but this gives a often enough of a prediction
cases then we would change that to profit okay just just to make
so there we go another another situation and we can see where it
profit declining and that's enough years that you know 11.5
and then profit declining and yeah so this this company is
there you know they were in uh in sad shape all right and we have
okay so we see another very very similar we'll do we'll do one
2004 school population was 1700 by 2012 the population had grown
again assume assume the population is growing linearly all right
now how much did the population grow so this a is really just the
so 2500 minus 1700 is 800 so it grew that much and then the
anything per year the rate that's the slope and we can divide that
just plug these numbers in and you'll see that we can see the
time zero 2004 1700 2012 2500 and i might even leave the hundreds
you know more exact we know that the population would be
so 1700 and then y minimum and then we have 2500 so then after
yes then my y maximum on the oh i put in the wrong so there you go
1500 and so in 2012 so time zero and then in 2012 so that's eight
so eight years later then it was 2500
so here we go okay so we'll have that and
x minimum and then the x maximum so let's just make it a nice even
and we could always change it if we need to y maximum 2500 but
further so let's make it 3000 and see if that's going to be
there we go and do i want the ticks for right now see if you
as we saw it will still give you the it will still give you the
default whatever python wanted to calculate and where you can
want there we go and for school population yeah all right so we
and maybe that's you know depending on what you wanted to estimate
the grid might be fine and you know if you wanted to you could
i think that works out so growing by 100 every year and we can use
probably growth per year was 100 there we go 100 x so the slope is
and there's the equation for the population for two years after
so we see you know we've done a few of these i think i think we
population model but there's some other form there's some other uh
in other tech all these all these are coming from that uh textbook
trigonometry because that's a lot of good business applications in
that just the notation g equals f of p the amount of garbage g
population p so we can go a g equals f of p and that's how we
of population and what that tells us is population is the
the dependent and population very often is an independent variable
trends so we look at that and we see the same type of thing the
thousand and produced 13 tons of garbage each week express this
so now if we have this one of the things that we would guess is
population then no people would mean no garbage so in our y equals
zero and notice we because we only get exactly one point here
so if we wanted to set this up you know we want to look you know
python scripts to solve this but if we want to set this up we want
how we're going to set this up 40,000 is going to be the
just call it in thousands and then 13,000 is going to be the
just call it in thousands and then 13 tons same thing i'll just
and then we say well that's one point where do i get the second
situation would i think that it would start at zero zero and if
back and say so here's zero zero and then remember our x values
so we'll call that 40 and then that's going to be 13 because it's
and therefore the x minimum zero fine but x maximum 40 is probably
um 40 is probably not even enough because we start with that and
and we can expect that it increases so then let's say the x
it 100 and we'll see y minimum zero now 13 maybe make it like 50
enough of a y maximum so there we go and we can just write this in
so thousands of people tons of garbage
so we have this trend here there we go 40,000 generates 13 tons of
and we can see this trend here so there's the rate here 0.325
0.325 x so remember the x value is in thousands so every thousand
according to this fictional scenario makes 300.325 tons so that
about tons 2,000 pounds so that times 2,000 would be about 650
but then if that's thousands of people so that's each person
less than a pound of garbage maybe so again this is this is not
you know a couple numbers that seem realistic and then what's the
would read this as f of five equals two so notice that the
that five is the input and any input or independent variable
even though we call them p and g here so that input five and then
so we would expect then that that means that when we're talking
then the 5,000 people would produce two tons of garbage so that's
five is the input two is the output so in our x y scenario here
that's what that would mean 5,000 people would produce two tons of
all right and so let's go over here to 89 and another one you see
alphabet soup of of this as people use different notation notice
of i would read this as g of a so it's a function of this input a
dirt d is needed to need to cover a garden with a square feet so d
and we read like that g of a and the common notation you'll see in
f for function and then often we just go through the alphabet fgh
talk about in python and pretty much across computer science your
have a much better name so you know that's something that computer
but nonetheless you'll see this all the time you know g of a so
input that's the area and then given that area then how much dirt
square feet area requires 50 cubic yards of dirt so that 5,000
to do any calculations to this but i just want to show you that it
so that's just how we would write that given that input you know
first then therefore how much dirt we need and that that would
write that there's we don't need to do any math to that right now
one so 100 cubic yards or 100 square feet of garden requires one
all right and number and question 90 we'll see just another
function the number of ducks in the lake after t years after 1990
five is the time years after 1990 so in 1995 there were 30 ducks
years so in 2000 there were 40 ducks in the lake and given these
find the overall equation plot the points graph it you know make
the notation here and this is what that means all right now 91 the
just answering these questions it this won't matter but this is
but we can still answer these questions because each of these is
each of these is still going to be the same now notice h of t and
you know again another way of expressing this so as x y values x
the h of one is 200 so that x value is t for time in seconds so
after two seconds it's 350 feet up and again this is not linear
the same things that we've been doing actually won't work for this
meaning of each statement here and 92 the one to one is this is
x value like each x value and y value pair up like that neither of
parabola because we see x squared and we'll talk about parabolas
that there's actually positive x values and negative x values that
so that's why it's just not one to one but it's still a function
i don't want to talk too much about that we'll get to these these
want to mention that in case you're looking at that and saying
so in number 60 now this is also not linear and you see the height
something like this after t seconds here's the function h of t is
seconds here's the function h of t equals negative 16 t squared
so that's showing that you know it isn't linear in fact it's a
around comes back down okay so the domain anytime we talk about
so the domain is all the x values that are possible here and then
the range is all the y values and this actually has a limited
parabola that goes up and then comes back down there's a maximum y
after that y value there's no more like y values beyond that are
it'll just never get to those numbers then the domain
numbers but realistically in the context of the problem time zero
domain so you see mathematically these other numbers exist and
but realistically if i'm launching something it starts at time
can talk about t minus whatever and talk about negative values
you know and this is second so if it's like t minus 10 then it's
10 and that's 10 seconds until the launch but realistically we're
and then the other one would be it does go up and comes back down
the ground again and beyond that it's not really within the scope
look at how we can solve this just because even though that's
i want to find out what that t value is when does it come back
negative 16 t plus 96 t we can go into this where we're going to
t we're going to make it x just because i already have x as a
and make a t that's fine so negative 16 and again we're going to
x and that's always the this is the equation set equal to zero and
makes the zero now negative six would not be
plus 96 t oh because i put minus
so it only gives us zero what if i have
so i was doing this with things that only had one solution so
just printed the first one but this does have two solutions you
could get really fancy here and then actually just make another
finite set it's not zero six as a coordinate it's x equals zero or
this zero and i could have another print statement
there we go to show the first one and but this is just a matter of
output to look okay so i'm going to go ahead and i'm going to go
show the first one and but this is just a matter of you know how
and we have these you know we also have the you know which we
you know loop through this to get solution to get multiple
x equals zero it's on the ground and then x equals six so that's
that we could graph this and we see that it back on the ground at
bit ahead because we'll talk about quadratics later so yes we will
graphing this because we'll get into this with quadratics but this
at six at six seconds later it's back on the ground so some
turned and i'll tell you this that you know halfway through these
through it's halfway through it's uh at its maximum point so we
what is that maximum point and we can do that math negative 16
so halfway through that so that would be three would be x and you
that you know we set up the situation where i have x and then i
zero six it's back on the ground so three seconds later it goes
so realistically then the domain for this function as that's
you know mathematically it exists but related to this situation
values that mean anything for this are anywhere between zero and
because everything else doesn't really mean anything for this
this then if it keeps going down like it doesn't go back down into
are between zero and 144 so that's my domain between zero and six
range between zero and 144 so you know these are some things we
when does it equal zero and plug in some various numbers
all right so if we look at 61 just again reading reading is these
any code for this we have this situation the cost of making x
and the fixed cost is determined when zero items are produced so
zero so then if x is zero that 10 x drops out and then we're left
it's b for begin you know when you know before we produce anything
now maybe this is some sort of business and 500 is like rent and
even if they're there they didn't make anything they still had to
and then they pay ten dollars for whatever you know for whatever
so then the cost of making 25 items would be 10 times 25 we just
all right and supposing the maximum cost allowed is 1500 what is
have to set this equal to 1500 now if we take a look at this and
so if we have 1500 equals 10 x plus 500 and notice i'm not this
worried about doing anything with this yet but then what do i want
to zero so if i subtract 1500 from both sides then i get zero
because if i subtract 1500 from both sides and so that's set equal
that's where i could plug this in here so you see you can work out
python code so 10 and then here i do need 10 x minus 1000 so if
one i know there's only one solution so if i keep the other one
i know there's only one solution so if i keep the other one that's
so whatever it is we know that we could only make a hundred
because you know maybe they only have that budget you know
hundred of them their total expenses were 15 total expenses were
you know then we have to go out and sell whatever they are i don't
whatever they're whatever else they're making all right
okay so we and we see these same types of things we i just want to
that at the number 44 at the start of the trip the odometer on a
at the end of the trip 13.5 hours later the odometer read 22 125
there we go assuming the scale is miles so average speed we want
anything like a rate like that that slope and we have two values
21 395 and then time 13.5 and then the miles and we can go through
about graphing this or not it still will output the slope which is
the average speed and that's where average speed it would be a
we know especially over 13.5 hours the speed's going up and down
sometimes faster sometimes slower but we get that average speed we
they're not going to that exact speed the entire time all right
gas station to fill up his tank and he looked at his watch the
started pumping gas in the tank exactly 344 the tank was full now
minutes especially with these prices these days i would be
money but he noticed he had pumped 10.7 gallons so surprisingly
but what is the average rate of flow of the gasoline so again time
we want to call it minutes we can call it four minutes and then
to gallons per minute or and again same thing plug it in you know
because we already did that subtraction is just 10.7 divided by
you have these scripts and everything available but some of these
even before you look at those or you could break it down into
in four minutes and you know the rate of flow per second but
gallons per minute is probably fine so we see all these situations
how we can set these up and the things that you're building that
an equation even if you know the equation is something else and
algebra you know because that's it you want to get it equal to
from earlier that one step of algebra so then you have it equal to
so you'll have these things set up solve any equation or you know
rate all that so you know if all you needed was the rate you know
bonus but it'll still also answer that question for you so we want
ways that we can interpret these questions and solve solve the
of some of the keywords and hopefully you see how you can apply
that you come across you know look look for situations in in your
you can apply these all right so hopefully that was pretty useful
factoring in algebra then we're going to talk about dividing out
something that we're multiplying and therefore i'm looking for
am i multiplying so when i see a number like six then i can say oh
times three and here i'll put the dot for multiplying to separate
know when i when i look at a number you know like 15 then what are
three and it's useful to be able to think about numbers and what
helps us reduce fractions and simplify other other terms so for
two numbers here supposing i had a fraction that was six out of 15
reduce that fraction to lowest terms there's a better way to write
that they both are divisible by three that three is a factor of
divided by three is two and fifteen divided by three is five and
is five and so this is the that reduced fraction and i got this by
factors and i divided out those common factors so just like other
thing to the left side of the equal sign and the right then it's
if i do the same thing to the top as i do to the bottom but that
and dividing adding or subtracting doesn't doesn't work so if i
reduce my factors i can even keep going supposing i had something
and supposing i didn't recognize that 20 that six was a factor of
were both even so i could then divide by two six divided by two is
i could start reducing again recognizing that common factor or
oh three and twelve both divisible by three and then i could say
twelve divided by three is four so again i factored things out and
now a lot of times you know we see things and we don't we see
especially bigger numbers we don't right away think about the
do long division in a couple minutes i'll show you how to how to
to find the common factors that way even if you don't see them or
do i go through all these possible factors i'll show you how to
to do that find those common factors but this is one of the big
and this is more related to other algebra topics we might not need
code but if i have something like you know 4x plus 16 something
the four the 16 have a common factor which is four and i can
and we can divide it out like this way so this is another use of
because i see these common factors and i divide it out 4x divided
put x and then 16 divided by 4 is 4 so and again this has more to
applications but i want to show you this because this is also
this i see the common factor and i can divide it out and it looks
the 4 4 times x is 4x 4 times 4 is 16 and get back to that so
one of the other things we're going to do is talk about factoring
and that also i'm going to show you how to do this but then we're
you know how to find common square factors and then factor them
if i have a square root and sometimes we have square roots that
not perfect squares but i can factor them and sometimes that helps
cancel out with other things later so if i have let's say the
5 that's great square root of 24 almost 5 it'll be some long
but if i can factor that out recognizing these common factors and
just any factor i want a square factor so if i remember that 24 is
4 is a perfect square and then i can say so i want to identify
the ones that are square factors and four square so the square
and then since i took the square root of four i still have that
if i can't square root the whole number i can square root part of
sometimes then even if i can't factor out something like the
something like this and that's the simplified square root this
that's really useful now again bigger numbers things that you
this a perfect square we'll talk about how to write the code to
divide them out and even use the simpy library to display it in a
the essence of what we want to do with factory recognizing factors
even if you're going to write code the more you remember your
things will be it just makes things you know come together a
looking at numbers thinking about what factors made that number
factors that we could possibly divide out and so let's take a look
the code so here we're going to do the same thing we were doing
the common factors dividing them out and it's going to work a lot
because it'll go through and easily find all the factors for you
the modules operator so modulus that is the percent symbol so on
five key so what that does is that finds the remainder so i
five modules three it's like five divided by three but the whole
want the remainder five divided by three three goes in there once
that's what it'll print out the two and if we want we'll just
just to show you another one so 31 module is 10 so 31 divided by
matter it's a remainder of one so when we run it it'll output one
for finding factors because a remainder means that it's not enough
but if the remainder is zero then it's a factor and that's what
find factors so i just picked this number 12 and we're going to
in our loop so i i made this variable just called test factor so
one to the number plus one because i'm dividing so i have to make
at zero it'll give me an error and i want to include that number
one otherwise it won't do that last number so for test factor in
here if number modulus test factor is zero then it must be a
out the test factor so that's what this is going to do given my
through that and try each number and see if it's a factor and
it see it prints there we go one two three four six and twelve all
12 so how can i reduce fractions to lowest terms so let's take a
variables here my numerator let's call it 12 denominator 24 now we
to reduce to one half and i'm going to define a variable called
a factor and who knows for some things that might be the greatest
my numerator to find the greatest common factor all right so for
plus one because that's really it i want to you know i want to go
denominator beyond that the numerator it's not going to really
module so we'll do this line here if the numerator modulus test
modulus test factor is zero so for each of those if it's a factor
now that's going to be my variable factor and then once i have
so i'm going to do numerator divided by factor and i want to cast
going to look nicer when we do you know the sense of this is that
factors so this is going to look nicer when we display it so once
you know it could stay at one or it's going to get you know the
i find that numerator divided by factor cast as an integer and
divided by that factor cast as an integer i'll call it d and then
original numerator divided by denominator and then the reduced
this and we see that the original was 12 over 24 and the reduced
any fraction and you can even copy this code and use it within
or you can put this as its own function and deal with it that way
functions out of a lot of this code later on in the course so the
adding it let's just do this so we had the decimal to fraction
we had an input rather than just have the number here i have this
a decimal number to convert and remember then that input gets
string and we've done this before converted to a fraction so i go
input you know how how many digits minus one well convert it to an
an and minus one because that it that will come in as a string
so there we go then that becomes my exponent and then i'll still
which is n and then as a fraction my numerator is going to be the
10 to that exponent so what that's doing is taking that value and
so there we go so the so n has all those digits including the
this line for the numerator moves the decimal place and then the
exponent so now i have an integer for the numerator this will end
the denominator and now what we're going to do is just like we
that fraction so same thing factor equals one everything else i
finding the greatest factor dividing it out and there we go
original number that the person entered and then print the
enter a decimal number to convert so let's convert something like
and it took it and it reduced it to one eighth which 0.125 is one
and we can run it again just to see that if i have a point zero
there we go the decimal and then that's one fiftieth as a fraction
into other things that we've been doing all right now we're going
factoring out square roots so this is all good to reduce the
root something now this one if i just print math that square root
the square root of 25 here is five great but what if i have
now that doesn't work out nicely and by default it'll just give me
if i want to factor it and this is how we want to factor it i use
square root of 12 because underneath the radical 12 is four times
square so the square root of four is two and that comes out and
else i can do with that so that's the factored square root we want
and divide them out the square root of that there we go so here we
make it user interface but i just put it here n equals 12 and max
that's the one that will change and here's i put this as the key
get to you know if i have my loop where do i start where do i stop
floor of math dot sqrt of n so i'm going to take the square root
that's going to be some weird decimal number now i just did this
one i probably could have done math dot ceiling also but i just
root and whatever you know math dot floor so drop all the decimal
drop them all and then add one so that's going to be the upper
here so for maybe factor in range again starting at one zero would
if n modulus maybe factor squared so you see i'm running through
you know each of these is the square root factor so if i square n
factor squared if that's zero then now that maybe factor is now my
and we're going to cycle through all these you know divided out
some factor that's what's going to be on the outside so then i
my original number the square rooted factor square factor and
of these out here like this because we're going to build upon this
step but to show that square rooted factor square factor max
that's left over so for 12 since we had that example earlier we
rooted factor is 2 square factor is 4 and the integer is 3 even
was just text it actually comes out as a float so what we have is
on the outside you know 4 was a part of our in-between step and
rooted factor and then the integer that matches up with 2 coming
factor that's the greatest one and then 3 is the integer still in
to use simpy to make this look nice import math import simpy and
so now i have this there we go and same variables i had before
square rooting it but then you know find a one more to see where
the like the greatest square factor i could possibly have so then
factor and then square they're all starting out as one and i'm
so slightly different variable strategy so if maybe for maybe
if n modules may be factor squared then we have the max factor is
all right and then the other factor is n divided by max factor so
the factor that i divide out because i'm squaring it here and then
the radical is that original number divided by max factor so then
this look nice we cast them all as integers so the square root of
want the square root of it cast as an integer and then that's the
square root other factor cast it as an integer there we go it i
we need to cast it as an integer here other factor and then the
variable output and we see it's square root times simpy dot square
that output looks like in simpy and this presentation here we
uh that might not make it look as nice but this simpy output so i
and then when i output it here there we go it factored out as two
and if i put it back to my other 24 that we were talking about
work out and so it factors that to two root six because it's six
root of four is two and that's what we're doing the types of
through we just want to translate that into code you know i'm
of that number and which ones are square perfect squares so 24 i
that are perfect square and i find that it's four and then the
the simpy makes it nice so we can do this to factor square roots
this we can divide out common factors we can reduce fractions we
and these are a lot of the things that you know we often do by
now you have the code that you you can do this
you can do this now that we've worked through the core skills in
let's look through some extra problems and i'm going to work
extra problems using the colab notebook so you can see how you can
you're building and use that use these to solve problems that
in day-to-day life so we're going to go through some more extra
to do a walkthrough of the first certification in foundational
there's five of them we'll do three of them for this course and
but they were i also designed them to be standalone that you know
you could walk through and be able to do all this still though i'm
uh maybe you already did this and you want to check some things or
uh turn out as you expected or you're stuck somewhere so you can
in in this video and see so each of these steps lead you towards
we've built upon each thing so the first thing you're going to do
notebook this notebook is read-only and this is what gets shared
so you make a copy and that copy is going to be in your google
uh and it will be in a folder called colab notebooks by default
it in whatever folder you'd want it to be you want it to be in and
for this course you're building your resources so you're going to
drive uh especially if you have other colab notebooks or something
folder for everything uh in foundational math one you know or
to call it that so you make your own folder you're putting all
have so you walk through as you work through these you'll
but then you also have some code that you can reference so you
i already did this and then each of these i have as a different
click on the triangle here to expand the next step and with each
then up here you have a table of contents that you can go through
you you can jump to whatever part you want you know you can add
making each of these a section heading so you do need to acquire
this is actually self-contained you're going to write the code and
code that you wrote and see if it's correct or not so this cell
maybe for other things you might do in the future you might take
this other library as this raw.py file in github and really save
and then you'll be able to access it so this i have the note here
at the beginning of every session and the only reason i said may
away for two minutes and come back don't count that as another
they do time out the runtime will time out after 30 minutes of
typing that means no running any cell or even if you are really
hours so then you you know you might say wait i haven't i've been
time out they have that time out too all these are security
leave it open for you know indefinite amounts of time all right so
this library and you're going to run it and we'll take a look at
and as this is going yep it'll save the library locally and then
so it'll say requirement already satisfied even though it said
i do this i already it was already okay that's just what it prints
test pass go on to the next step then you know you're good so it
you know now we have this library available and each step will use
four yes i do have add subtract multiply divide i know you know
know how to do them in python but it kind of walks you through
the notebook you might be already familiar with it but so you know
so we go through just you know two variables and then you're going
with the comment change the next line now this was just add so
a plus b and i'm going to click run and you see two plus one is
passed go on to the next step so we go to the next one subtract
c minus d and i could hit run or i can hit shift enter which i'll
so this is just getting you familiar and then each of these
so you've run that first cell and then you have the test and
code and tell you one of these steps in a little bit i'll do one
and you'll see what what it'll tell you so here we go so we'll
multiply in python like a lot of things is the asterisk same key
the eight so just hit shift and it's above the eight there we go e
passed and then we divide now when we divide here g and h now they
happens to work out but if i had them as numbers that didn't work
defined as integers then i would have to do something else because
and if i divide it won't work out the answer will be a float but
this you know i just define g equals h equals and when i divide
time about whether they're integers or not it's just going to
so you can and a lot of things that you might work through here if
you might just have things where you define your input or your
actually just prompt for input and so in that case you don't have
when when you run it it will prompt for input and then that could
that you want that way you don't have to worry about changing the
a positive integer it actually could for what we're doing here it
just put that there and then we just cast it because the input
and then i need to cast it in this case as an integer to do some
all right so i need to do an integer or a float and then the only
following that model i have string b and a lot of these have you
there that won't break the code but you do need to change it all
going to be this and you absolutely could just copy this and paste
what if i just change this now that's really all you need to do
just for me i feel like you entered one i want to say enter
and i want to cast it as a string as i want to cast as an integer
that now so i don't need to tinker with this at all so i might not
to another or something like that that you know we'll see all
there we go so what i was saying is if i wanted to change you know
not be central even if it gave an error it shouldn't stop you all
casting it as an integer and adding it we're fine if i cast each
divide it would give me an error oh but i didn't want to worry
defining them as integers we're just adding we'll cross that
and we can get input and cast it on the same line so notice just
i'm going to do the same thing here i'm going to copy this whole
because that's really what i want to do
all right now here's one where i really don't need to do anything
change that to another now just the way i have it
see it actually just tested a bunch of these things because you
part of the line and you know i really didn't need to change that
your into your input should be this now my point here is this will
from going on to the next step so you know maybe that's it maybe
in there that like why why did it say it was never it looks
and maybe you're watching this video because that's where you were
from going on to the next step and in fact you know that's fine
what was different i'm not worried about it on to the next step
okay well maybe i just should have just said this you know you
check it and then see there we go and then and then you can make
is that this is supposed to be just you know a teaching tool check
move on but you know not to get you caught in something that you
moving on all right now as i was mentioning about dividing casting
number allows for decimal places and most of the time i'm just
anyway because just in case somewhere along the way i need the
situations where i might definitely need an integer certain simpy
that soon enough and counting but other other numbers that i'm
to cast it as a float okay so again prompt and then cast as a
the same thing and that's okay you need you know if you copy you
and need to know exactly where to put it but there we go and we
number enter a number and see now we will divide so i definitely
i didn't even say integer i just said a number so this is going to
enters in and then when we take a look then you see it's waiting
three enter number four and 0.75 which is perfectly fine because
good times all right so order of operations and yes python knows
so in case you forgot you know here's the acronym PEMDAS
uh parentheses exponents multiplication and division addition and
you can and then remember the python syntax for exponents is the
what i wanted you to do is test your knowledge of order of
about actually writing code here then you're going to put your
really think about the code see if you can do this in your head
and then you're going to put that here well you're going to put
when you run it python is going to calculate the actual answer and
you'll see all right so let's look at order of operations
and then multiplication and division as they come up so
uh four times two and then we have 14 divided by two so you can
multiplying and dividing all day so as they come up four times two
divided by two is seven so then we're going to have one plus eight
eight is nine minus seven is two so then we take two now we're
two to the third power is eight and so there you go put your
and there we go actual answer is eight your answer is eight code
okay so all these things and remember you can just like the other
put print statements you know all whatever math you want just
statement python will do that for you so those are some simple
okay so remainder remember when we divide something that does not
and the modulus operator looks like a percent sign but if i'm
it tells me just what the remainder is there we go so as i have
four is two but with but as a remainder so two and then two left
would give me two because that's the remainder or 14 divided by
so if i do eight a modulus b and again it's the percent sign on
key as the five but you have to hit shift so 14 divided by six now
by six is two with a remainder of two so that's what we're
printout there we go now actually we could we don't need to do
well supposing if i had 15 divided by six so six times two is 12
and so a modules b would be three if you wanted to you can test
this particular code is testing did you do it correctly here so if
try some different things whereas then if i go to 18 that works
be zero there there would be no remainder and we can use that to
statement here so if i have 20 modulus five so that's 20 divided
so 20 modules five the remainder would be zero so if that zero
a factor so you see we're using the double equals to test it so
we're going to walk through this and we're going to cast this
factoring really only works with integers if you know we can
you know if it's a factor there's going to be a nice integer in
enter an integer so input cast it as int and that's going to be
next one enter an integer to see if it's a factor and again cast
to be test factor because i don't know if it's a factor yet and in
number now remember whatever this is if it's true it's going to do
it will then it's going to do this but we're going to change the
modulus test factor and then now if that divided by that gives you
then we can say true it is a factor and then or else it's false
it's false so there we go and enter an integer so let's do one
and we can run it again and let's say make it 12 3 true so there
things and we can use that to test if something is a factor that
but we're going to take that and we're going to build that into
factors all right finding all the factors of a number so very
not asking for second input here we have the first input and then
so now i have my for loop for test factor in range so i'm going to
let's look at this backwards here i'm going to take this range and
there it would start at zero but i can't have that because that'll
right away so i'm going to start the range at one and then end the
because normally the range it won't do that last number so i have
whatever that number is i want to include that all right so now
it's going to loop through everything every number in this range
is going to be one and then the next num next time through the
so it will just loop through how for that many times yeah for
all right and this is what we're going to change the if statement
so number is our in is the original number we want and each of
want to do with it we want to say if number modulus test factor
equals zero just like we were doing before we're just kind of
so i get this number and i'm going to loop through all these
and i'm going to loop through all these factors from one up to
by test factor gives me a remainder of zero then it is a factor so
all right so we run it and what do we have let's say 12 12 is a
and you see it'll print them all out 1 2 3 4 6 and 12 and we can
supposing enter like 17 1 and 17 because it's prime so that's what
the factors here this type of thing we will revisit this at
to lowest terms okay now what about prime numbers so a prime
are one in itself so we're going to and then anything that's not
so if i have you know five is prime because the only way you can
five but six as one you can do one times six but you can also do
you have those other factors it's composite so here now we're
and again integers because we're looking at factors and i'm going
variable prime or comp say being prime and then same thing range
two because one will go into everything and that's not what i
does that won't tell me anything so i'm going to start at two up
again not including the number because this this this time it
didn't add the one there because again same reason i didn't have
we know that those are factors but i want to find out from two
if it's a factor and very similar then if number we're going to do
always go back if number divided by test factor equals zero there
variables here you always double check just in case the variable
different way of doing things but yes if that test factor works oh
so this would have given me an error
and and that's the thing with with reusing code yes we know we're
and paste because that helps you know if it's a whole block of
it is exactly the variables and everything that match up correctly
people do too much copy and paste and then they're lost because
so this one we call it test number so if number divided by test
of zero then that means that is a factor which means all it has to
means the number is composite and it's only prime starts out that
prime only if it goes through and we never get a factor here
so let's take a look if we have this and enter a positive integer
composite right because i can also do two times two and then let's
prime and that way you can check all kinds of other things you
is it prime is a composite there we go and you know now that you
change any of the code when you run this it'll you know it'll uh
interesting things reciprocals so writing it in math it's the
reciprocal of two-thirds is three over two you see it just flipped
the reciprocal of five is one-fifth because any whole number it's
denominator of zero or sorry sorry denominator of one so that'd be
it's one-fifth as the reciprocal and you can multiply a number by
there we go pretty good so and there we go zero has no reciprocal
so we can write the reciprocal whatever the number is we can just
there that's actually all you need to do to find the reciprocal
and some of these might be decimals but nonetheless this will find
and we see our output here enter a number and what if i have the
um five see point two but that's the decimal equivalent of
all right so just putting this in there showing you what you can
other things we can do with the input is supposing i wanted to
and are two numbers separated by a comma oh well now but i want to
so i can split it so this i'll store it as the variable nums still
and then here this is actually going to be an array in this case
to split it at the comma and then now this array sp has two
i'll cast that as a float and then i have sp1 so that's it you
by a comma split the input and then then cast each of them
and notice the code here just says cast it as a float so float
over here there we go and then what do we want to do and that the
the two numbers so that's why we cast them as a float divide the
by b all right so there we go split it cast it and in this case
okay so and our two numbers separated by a comma and let's see how
um this one will be a repeating decimal of eight comma nine
there you go i'd notice if you have just one number repeating the
that number over nine so point one repeating would be one ninth
two ninth and this one eight over nine so there we go okay now
is building up to you being able to factor square roots but let's
so factor multiplied by itself is a square and it is kind of like
sides would be the same or all sides would be the same so when i
they're the same and so is that number times itself and we would
the second power okay so all we're doing here is you know we're
getting the square so in this case it's going to take the input as
it there we go okay there we go number square all right five i'll
okay so let's go the other way square root function so anything to
it's squared but what if i knew the result and i wanted to square
of my square yard but i want to know what's the side side measure
first thing we're encountering here that is not built into python
library and this is where colab really helps you out because a lot
through some other things to install things you know in other
math and you don't have it behind the scenes it works you just
all right so a number to find the square root definitely going to
all right and how do we get the square root of that once we import
sqrt and we call it a number n
especially you know think even if things don't come up
open parentheses one two close parentheses one two we got it so
and we see here and remember to find the square root so we'll do
about 16 square roots four and we can do another one that doesn't
and it'll give you a bunch of decimal places
i remember yep so 4.5 yeah about there we go okay
okay other cool functions the floor function this is another one
so the floor function so we have a floor function which just drops
and there we go drops any decimals and sometimes called integer
so even if it's like 3.9 it's going to drop and just go down to 3
we have the ceiling function which as you can imagine if floor
is no matter how many what decimals are even if it's 0.1 it goes
round the one we use possibly most often round remember 0.5 and
anything less than 0.5 0.4 and down rounds down so we're going to
function here all right enter a number decimal place and we're
math dot floor function here math dot floor of n so enter a number
to call it 5.99999 and when i hit enter yep and that's the floor
drops down to five so there we go and remember supposing you went
you know i'm upside down ceiling function supposing i wanted to do
um 7.1 because that should round it up to eight and so that code
what these directions are it'll tell you oh you should include
end up trying different things it doesn't prevent you from going
either if you spelled it wrong or something or you did something
floor and go nine point three
right good drops it okay so we're going to put some of this
all right so a few things we've already done we're going to import
we're going to enter an integer to define the greatest square
i'll call that max factor and right now it'll be one and then the
stacking on these functions here uh the math dot floor of math
but then we're going to add one to it so we want to find the
number you enter it in we're going to square root it that's going
decimal places and so we could do the math dot floor and then add
now i realize that i could have just done math that ceiling and
for whatever reason i did this i like it so i kept it but there we
so that gives us the upper limit square root of that number and
number now what do we have now in my range from one to upper limit
that was the square fact the square root factor i square rooted it
that range so it's going to go through and maybe factor is going
be two it's going to be three you know up to this upper limit so
equals zero so that's it these these factors if i square them is
that out and if that is then max factor you see it's not going to
you know that's and that's the idea with some of these change one
think about what you're doing then we see yep i'm going through
and then finding square factors if n divided by maybe factor
of zero then max factor equals maybe factor so that's what we
so and again knowing that these were the square rooted so for our
we're just printed out squared
so we'll see this here so if i have something like 12
all the greatest square factor is four because two you see it
that and that's a factor of 12 three squared is nine does not work
here okay so here we're going to build upon that code and then
because when we look at factoring out square roots that's kind of
when you have a square root that doesn't work out perfectly but
that's what we want to do here so i still have get the same
all these variables equal to one because we'll change those square
all right and then take a look at what this is doing same thing
got that same upper limit and so still maybe factor is going
check for square factors just like we did before
there we go and in this case max factor equals maybe factor
squared there we go and then other factor is n the original number
there we go so what we have is the result is going to be that
this times this and we're just looking at how that divides out so
you don't need to change anything because i i thought that this
a little bit complex to try to follow like what what i was
through so i didn't didn't want to have you have to change
going on here how we're dividing that out and then when you run it
to factor maybe i'll do the same 12 here see 12 equals four times
let's say 50 50 equals 25 times two and again that first part is a
there we go the last four steps prepares you for this so factoring
of what we want 12 if we look at the square root of 12 is four
perfect square the square root of four comes out and it becomes
kind of building as we're building this code to do is this
i'm finding the greatest square factor and then that comes out
two two is on the outside now all right and in doing this we're
we have square root and for our final output we're going to import
going to give us a nice output at the end that looks like this so
that's the thing you know python outputs a certain way and then if
that looks more like math symbols that's what we have symbolic
similar input without the radical and our square root factor using
dividing these same type of thing where we're finding maybe factor
now in this case i kept it like this maybe factor squared so the
max factor squared and then we divide so now we do the output so i
yes and i realized that up here there's maybe factor squared and
rooting it again and the key is casting it as an integer because
point oh did not want to do that there yeah because this will be
okay so that's the square root and then remember other factor out
that max factor and if there's anything left over other that's
that as an integer and you know that's it i'm just taking this
as an integer and you see that you can do that with variables so
and now the output is square root which was this variable up here
square root is different than math that square root and using this
be my last i want to be that to be my last thing is this output so
this for the test that's why output the word output shows up here
but notice it's not a print statement it just says output and the
and it will display it so these types of simpy displays sometimes
okay so what do we have uh let's take a look at our um
let's take a look at 50 as we were talking about before
so and just because this came first that's why it says test passed
but 50 factors out to five root two
and if we run it again then we have you know go back to our 12 12
and we can see how we can factor out these square roots
so there we go this is now one of the things that you can do
and this would be a bonus we could do this later is we already
you could put all this in a function
you know all you know you don't need to the testing part but the
the testing part but the output you could put this all in a
for you so just like you have math that square dot sqrt to output
decimal you could actually make your own function that would do
you know like this so some interesting things that you can do and
you to see the build-up of this and how we can use these you know
to factoring a square root which is something that's you know
useful for some math you get into and then you can write code to
all right here's some rounding just interesting things so if i
whole number if i have something like this if i round comma and
me how many decimal places and if i have this round and it's a
big numbers so that will give me that many zeros so there we go so
millions the second number rounded the sixth decimal places so and
my print statements print round and the first number six zeros so
and then the second one print round
be and i wanted three decimal places so it'd be three
there we go and we can print so that there's my six decimal places
i don't want it around to the next integer it already is an
14 million 500 thousand rounds to 15 million and then the next one
all right there we go and fractions decimals and percents
percents so we could see here and we've done some things like this
here we're going to take the input as a string see i'm going to
the input as a string and as a string every string has this
string so i want to take the length of that string and then i need
now remember the person who enters this in is going to put a
i have to subtract one because i don't want that decimal place i
without that dot all right so that's going to be the exponent and
now my input digits i'm going to cast that as a float so the
10 to that exponent and i wrote it all out just to make it clear
anything with three decimal places it's going to be times 10 to
going to move the decimal place over and then my numerator is
and the denominator is that 10 to the third oh 10 to the exponent
oh 10 to the exponent there we go so there's my fraction and this
anytime we're converting fractions but now we're just writing code
so how many decimal places that's really what this is essentially
how many decimal places am i talking about and then that number
places 10 to that exponent and the denominator is 10 to that
because now that i have it as numerator denominator now i actually
go back to n if i want or i could put numerator times numerator
one but i could do n times 100 which it's always times 100 because
and so that's it that's the first two digits are there are your
the percent and we can run it so if i have somebody enters in
five there we go so the decimal is point one two five the fraction
over a thousand and the percent is twelve point five percent
so there we go converting any input fraction decimal percent
percent and this is where i was saying that you could you could
this you can define a function here where you can execute a block
so you know here's the function definition d e f and then the name
open and close parentheses that may take input but they don't have
four spaces one two three four so d e f name of the function colon
it can be as many lines as you want and it can have comments just
and then there you go here's one something outside the function
it's then called it it won't do anything until it's called here
so i could have this function definition and if i took out this
again so now it'll have this is outside the function then it'll
and then back outside the function
there you go now change the name and remember to call it so
there we go and then we want to run it then change the name to
because it can't spell function without fun
so if i just change the name i'm gonna call it fun and now i'm
so that's what is the function call is when i you know when i tell
now there you go same thing to show you how to define a function
and then here's one with input
so it can take input any input we're going to call an argument so
um now right here it's telling me that it's uh you know called
it's going to take this input which will store its variable name
here and it's going to print hello whatever the name is now here
at the end of your function skip a line at least one line so then
definitely not in the function and then the input and casting it
and we'll keep it that that way what is your name and notice
indicate a new line so now when we run the greeting you see it's
and i'm going to pass that into the function so now that function
going to be this variable and then it'll do the greeting so here
hello there we go and now now that you see this working this is
this because it's like remembering where these are
so you know greeting and then when we call it i'm going to change
there we go so we see you know where these variables are
function like this so then you see you know this variable how do
as an argument there and then in the function definition it's
something with it but the function of this should actually be the
yep see all good and these functions which is kind of cool you
input so we have this so i can have multiple input in this
you know do something with it well we're just going to add them
for any formula you have you see like i just made this add but you
formula you have make a function out of it so notice here you know
as three and then it's going to expect three inputs a b c and then
c and now down here i have to call it with all three variables so
existed before but then it just stayed there floating not doing
here you know now that we have have this i'm going to call the
because the function is expecting three inputs and then it's going
so we see enter a number and i'll enter a number
and another number six another number seven oh because there you
hey fun with functions now all the this function and the ones we
statement as a way to show output and that's good but we could
value so notice this function here then it just returns that that
and what that does is it returns it right where you call the
right where you call the function so notice this if we're going to
you know there's our input it's the float i don't know stored as
what i print is your number multiplied equals and then right here
it's going to be that function i call that function with variable
and it's just going to take it times two
all right so notice some of these you run it and then we're going
it again so enter a number all right there you go 16 your number
so all we're doing here is changing the return statement multiply
everything else we actually can keep the same there you go enter a
enter a number 16 and it's 48 so that's the return statement is
that's where the number shows up your number multiplied equals and
returns that so that's pretty useful sometimes because we want
where do i want this output to be right there and so we put the
so that's the return statements good useful statement here so we
things we have all these functions we you know we're looking at
solving some things you can even just solve for x and there we go
now notice here we're importing simpy again or for our symbolic
it even further from simpy we're going to import symbols and from
import solve so all these now i'll just define it here x equals
in single quotes so that's telling us that we're going to use x as
and the way that simpy solve works is the equation has to be equal
so at what i'm going to do all right well we'll see
here's the output solve for x and i even have this here zero
enter it in now what this does simpy has this built in solve and
be right here so that solve we know that behind the scenes it has
equation using the variable x and this is just like a subtle thing
another time but this returns a finite set and for this we're
answer that we want equation zero so enter an equation and then
answer there we go all right enter an equation and so if i have
minus eight so we can see that x must be four
four and i'll put it there now if i didn't have this
i'll do the i'll do the exact same thing two times x minus eight
it just the way it displays it because it's a finite set now that
to possibly if i put in something that had more than one answer i
too if i have let's see i'll run it again so supposing i have now
even if it doesn't work out to a nice integer but i'm going to
you see negative three and three it does have two answers and
function x minus four so there we go
if you didn't get a syntax error you're ready for the project
so different things you can do so this is where we now can make
and this is where i leave it open to you how you could do this you
like you could take one of these functions here like the factoring
yeah so you could take this factoring the square root and copy all
all right so as an example of something something you could do and
this now what's interesting is you as defining the function here
and we definitely want input and i'm going to make it n
and i'm going to make it n so we could do this that
it factors the square root and you could make each of these then
indent everything now since we're factoring square and we don't
delete that and here we go use you know we can keep all these
and this is the thing with a function
is you do want everything to be and you can take out things like
there we go then this has to be indented
and this has to be indented there we go and all of these divide up
and we see that we have output okay
all right and this part we don't need you know
and what do we want to do we want to
yes this stuff does not have a test because this is so what you
square root and then down here later we could try to call it
square root and you know uh let's see 20
and oh maybe I have to return the output
it's actually kind of funny that just popped up but there we go
so you see the output but because it's in a function we have to
all right so this is you know this is not the part of the function
and these are some things you can do because then you can you know
just define them in your own you know colab code cell with some
you know you can make them all functions but that's the idea and
if you wanted to where you just have um
which one you know what function should you run
should you run you could do a table of contents there too and then
you're building this multi-function calculator you're putting all
a colab notebook that you're going to be able to use and it's
calculator and then as of making this video I can't tell you
but hold on to it and then you'll see where to put it together for
getting the credit for passing this part of the certification and
all right so hopefully this was useful you know how to work
how to put all this together into this certification project and
there's more than one way to do all this so find find a way that
making your own calculator all right and we'll go on to the next
so with graphing a system of equations we're looking at really
on the same x y axis and we want to see where do these two lines
two lines cross that's going to be the solution to our system of
have two equations and this one's y equals three x plus ten and
so let's say I don't know it's a place you like to go let's say
so four dollars times x which is every time you go then y would be
have a deal oh well if you pay ten dollar membership fee then your
so there you have the the decision like okay well with this
but when would these be the same price you know how many times
the same price so we want you know that's just one example of the
so i put these both in y equals because we're going to get into
but we're looking at just how this graph plays out here so if i
so without numbers here we're just going to estimate let's say 10
how we plot begin at 10 and then up three over over one and let's
like this and let's just say that's the line and then we have y
it begins at zero but it's a steeper slope you know be at zero
say you know it looks something like this and then they cross
intersect that's going to be the solution to our system of
there are numbers here and it was you know somewhere around 10 so
that that would be like 10 you know 40 something like that you
there so you see where these cross and depending on what you're
clearer to see might be harder to see but we can then always test
that's where that's where these lines intersect we can plug that
so if x is 10 so it would be three times 10 plus 10 and then y
that work three times 10 is 30 plus 10 is 40 yes that does work
you know four times 10 and y is 40 and then that works so that's
were doing this you know old school plotting a bunch of points i
y table and plot a bunch of points i was using graph paper and
and the reason why i didn't worry about getting this you know
drawn to scale is because i want to just you want you to see you
together two lines on the same graph my question is where do these
we're going to look at the code how can i set up a graph how can i
and you know for whatever the answer might be however you know
might be how we can find the solution each time so now let's take
you remember graphing one equation on a on a cartesian plane this
different one of the big things though is we're going to use the
so we'll talk about that more in a second but the first thing we
import numpy now you know this plt that makes it a lot shorter
dot pi plot numpy we shorten it you know it's just a little bit
you know the common abbreviation so we're going to do that and
throughout throughout this code so like before we are going to
our range x min x max y min y max there we go and one of the
instead of creating a loop like we were doing before what this
of x values and the first thing we need to do then is to find how
i'll take these x values you know notice x max minus x min so how
and that should give me an integer number but i'm going to say 10
that's how many points i want that's actually going to be for
need that many they it displays very nicely for anything with a
probably plenty and for some more complicated graphs you might do
me the number of points i have and just again based on these so if
this updates automatically and then here's where i'm going to
so using that library np dot linspace and it gives it takes the
and then how many points so there we go it's just going through
and and how many points in between and i'm just storing that as x
as my x values hopefully this is looking familiar setting up you
for x and y and here's where we're going to plot line one so in
two times x there we go and what it does is that will take each of
needing to create a loop it'll go through each of these x values
dot plot x and then y1 so here we go i have this and the second
y2 equals and this one i took it beyond linear i just made x
it up a little bit and so there we go that's my second y value and
plot here x the x values and then y2 so there we go to find the x
when we run this there we have it we have our each axis that first
light blue line and y2 was the parabola now that's a pretty good
had fewer points let's just say even two times this yeah that's
still going to see this become choppy yeah wasn't that bad but if
one times this then it really becomes a lot choppier because i'm
and there's a lot more going on here but you see how that linear
out just fine but this one yeah so that's why just as a default
we go and then to graph anything else all we have to do is change
oh okay well how about if i make this like negative negative 3x
three times x there we go if you write it by hand you know doing
you forget the multiplying so that's the key python syntax you
um and let's take a look at this and maybe we'll make this one um
there we go just to the third power how about that so there we go
and this one here cubic and we'll run this
you know even this yep the curve looks nice
so there we go all you have to do is change y1 and y2 and you
two but a lot of times we're going to do linear equations and have
questions where do they intersect so there we go numpy and use
the core skills in this unit let's look through some extra
extra problems using the colab notebook so you can see how you can
you're building and use these to solve problems that might come up
life so we're going to go through some more extra problems here
few other things you can do with graph with graphing and one of
lines or just in general above and below so if you have an
below the line we see we don't need to import anything different
the graphs you've been doing set up x min and maximum how many
for your array and we've been doing this before here's the line
now this one if you're doing an inequality you could also add the
a dashed line but this might be hard to see this line but here's
so we're going to say from x at still the same x values and then
two y values from y1 up to 10 and you could define that as a
already set our maximum or you could actually say up to y max like
this one we call it you know we want to make this red so that
give you a default but you know you can define these and that
go the fill between same x value and then you have the range of y
to work and we'll do a few lines here we'll make make some art so
familiar define the line and then plot there we go but then we're
between that x and y2 and y1 so you see you can define it even you
up to the top this one i'm going to go up to the other line and
line and here we go so fill line three very similar and there we
different face color and this one's going to be green where am i
between this one that we've defined up here y3 and y2 so that's so
are just going to be a band and here we go i can do this one
notice all these are just simple linear equations to show you this
two so what happens when we run this so we see we get the first
and then from there to there from there to there and there we go
let's say all right we see this red we see this yellow so if the
there i went up to y max it would just overlap and i know you
thinking hey you might have might turn orange you know yellow
it's the order of things that it graphs this that was red but then
it overwrote the red and if i wanted to i still call it a line one
down here so now this is yellow and then this whole thing would be
and remember because the yellow started down lower so the red will
but it didn't go down this far so the red didn't cover this so we
you know the yellow line was x plus three and then the red line
had that little gap that you know when the red went on it didn't
right but then we can you know y1 and now this one i definitely
y1 wasn't defined yet so you see it gave me that little error
make this official before we go on to the next thing
and we can see so since i've moved a few things around before we
let's change something else here i was saying that we need we
the red line and the yellow line the dashed line and it might be
can always hope here so single quotes and then i'm going to make
thing with this one the other argument single quotes and i'll make
two would be dashed lines instead of a solid line it's hard to see
there we go and because these you know with the shading sometimes
the exact line i mean mathematically you might just be in the
line but the way it shows up on the graph you know it's not you
it's nice but sometimes you might say oh okay if i'm making some
want or need that extra line so there we go so there's some
draw lines shade above and below and you can be you can get
of all sorts of things and this is essentially you know what
you know defining each individual pixel but defining the lines
equations and then that way you can scale things because let's say
change the dimensions of my graph i could scale this line with the
so that's the advantage vector graphics you can make larger things
size because it's all defined on equations anyway so there we go
with that other cool things you can create an interactive graph
interactive we're going to set up some sliders this one's called
across some python code that defines sliders that actually uses
works too but here's what we're going to import there we go in
to get us to be able to adjust these sliders and see the effect on
so there we go and then this interactive widget so i'm going to
is going to happen within this function so i'm going to define
a simple slope intercept so i'm going to define the function of m
for zoom so notice all of your dimensions here are based on that
and then we still have the points and the plot that's my y value
takes these inputs and here's the slider it's really the most of
is right here on this line so interactive plot now i can make that
just decided to call it that and interactive open parentheses so
am i going to run and i made it f and the main reason i made it f
of code was not that long but there you go what function am i
some ranges here m will go from negative 99 b will go from
so notice the zoom i could make it really small and x min max you
it's still going to be square but i could zoom it really into just
or i could zoom it out to 100 and i could change that number as i
we have is this and when we run that interactive plot it's going
sliders and then run this function so let's see how that works so
puts everything right in the middle
so my slope is zero and b is zero so you might be able to see that
this blue line is on there because it's a slope of zero zero what
see look at that now i have a slope of three and as i move up b
different place it begins right there now we see it starts right
bring this down and you see i can zoom in
pretty cool and see this is what i zoom if i'm so zoomed in one
so that's off the graph now i'd have to move that back now you
and these are some cool things you can do with your graph you can
even if you you know you're graphing all kinds of things you just
this is a nice way to zoom and you know you might see some things
where you can zoom and here's how you can write the code you can
graph that zooms in and out and you can adjust some other things
cool things you can do and i just want to you know it's a good way
slope and intercept as they change how does the graph change you
and therefore across the y-axis down here and i can change the
all the way so now i'm really zoomed out and it it looks like this
because it's so tiny it only crosses at negative three and my
go some interesting things you can do with zooming and you see
interactive plot and then your function all the graphing happens
okay so here's another interesting way to graph we can actually
to lead you to working with data science so let's just get a
else created this library this mediostat library for getting just
um here's you know the weather information that they take time
temperature maximum temperature precipitation snow wind direction
the maximum wind gusts air pressure and the amount of sun so there
solar panels you can calculate the hours of sun at a particular
wind turbines you can calculate wind speed at different places and
this one you do need to install this and so we're going to run pip
install this and so we're going to run pip install and i just made
it's a its own separate code block and there we go we just see
that installed this so there's a lot of things already built into
we've imported some things but didn't need to install anything
therefore it's not already built in so some of those newer
really pretty straightforward pip install mediostat done so
we can import it date time that was our i was already at python
do need to import that and then now we still need to import this
this data so that's why we import that and then the install
these i've included the link here you know for all the
all right so here's how it works start we'll define these
time year month day year month day so i decided let's do like the
so we have uh uh created a point now the point you create this is
so they don't have really built in like type in the name of a
you want to have an idea like let you know where you live you can
and longitude of where you are you can find latitude longitude you
you want a particular city somewhere in the city so the example
look this up you know somebody uh did this for british columbia so
philadelphia so there we go so here's a point in the middle of the
we can just get the data here so from that point so there we go
um there's my data point philly and start and end so there we go
you know start date end date location and then collect the data it
this does work using the same variable data equals this data
it works out and this one i just said hey let's just plot the
it looks very similar data dot plot and then down here we have plt
we need to do it actually all the rest of it the dimensions and
labels graph happen automatically so there we go we just have y
these three things so when i run it we see the average temperature
so all these things we know in a previous video we were talking
legend how to label the axis and everything this already does all
it'll just graph what you have here all right so there we go and
celsius so there you go if you're in philly you're like hey it
time but yes this is celsius so notice it's going way above that
and then we can just change this that we can have temperature
that and maybe we'll do one of the other ones precipitation prcp
and we see so average temperature and then precipitation
there we go pretty cool and we can see and of course then you know
here snow now what you can see is all right if there's average
and then precipitation then you'd expect hey maybe there's going
so there we go snow is in green and you'd think look at that
and there's precipitation and below average temperatures but no
average temperatures but no snow or below zero temperatures and
happened but just there we go here beginning january some snow
we go that's it so interesting things you can do and you know even
this on your you know having the colab app on your phone you could
something you know related to uh you know write write another line
today's date or yesterday's date and sort you know use that as the
app and click on click on something run it and you know see the
wind up till now if that's interesting you could do some other
things we can do with graphing and you see just getting a little
python is so good for data science because a lot of people make
a few lines of code and get the get the data you need and
powerful like that and you see the the graphing that we end up
library so pretty good some some cool things you can do with
theme that you know next we'll look at solving equations and
which ends up being tricky but we'll show you how to do it okay so
with it you know set up some you know some you know weather
okay now we're going to look at how to solve a system of equations
and you can still picture the graph the idea that that's that's
equate these are two equations two functions that you could graph
to get the solution and sometimes for solutions that it might not
then you know maybe it's you know not in a nice integer solving
time so we're going to look at how to do this just on paper or on
code on how to do this and set it up to be able to solve anything
so if i have these two equations one of the ways to solve this and
is if we notice if this equals y and this equals y then they can
ten equals four x so we see that if that equals y and that equals
three x plus ten equals four x and that's a little bit of the
so now we can solve these what can i do to solve for x i can
and then i get ten equals x now once i solve that x is ten well i
i need my y value and i can plug this in to either equation so i
to plug it into here so y equals four x then i could take that and
and that gives me y equals 40
and then that's how we would get the solution we can set these
and then solve solve usually for x and then plug that in either
get our y value now this is very similar to how this is going to
one of the things that makes uh sim the simpy library and solving
bit better is this works out nicely when they're equal to y and
equations that were not equal to y or something like that with the
and we would do the same thing with this is the idea that i would
equal to zero so i would end up subtracting y here so i would get
and i subtract y from both sides equals zero and that's the
when i solve it with the code and then the same thing here you
and then with each of them set equal to zero then you will see how
simpy library but that's that's kind of the method that python
advantages of this is they could be in whatever form they want
side of the equal sign just subtract it over and then now you have
you can solve it so you know and there's many other ways to solve
that's kind of the couple ways i want to show you you know this
set these equations equal to each other solve for one variable and
and then we'll take a look at it now so let's take a look at the
simplest way to solve a system of equations now this is especially
so you want to set each equation equal to zero but as far as
you know it doesn't have to be simplified just as long as it
use simpy our symbolic math library and i'm just importing
so that's the asterisk there and we're going to define x and y as
there we go x y symbols and now here's the equation set equal to
and the second one here then i just defined it as first and second
solution so this is the lin solve is the is the formula from simpy
the extra brackets first comma second so it takes this as
equations and then the next argument comma x y in an additional
symbols so linear solve these two equations because after each set
them equal to each other and use these symbols and when you run
comes out as a finite set now again the simplest way is there we
one line that puts it all together you can just change you know
run it and you know you see your answer it's pretty clear it's a
three supposing i want it to look a little bit nicer so still
and these symbols still have the same i'm going to use the same
now here where i have this solution here that's the same line but
variable is going to be a finite set but there's things i can do
another variable x solution here and i'm going to take this
behind the scenes it's a two-dimensional array so i want the first
also a two-dimensional array solution dot args zero one so having
a coordinate pair so there you all print the parentheses x
closing parentheses and then when i run this there we go it will
three in parentheses and i can do other things with that now there
want to see the graph now this gets tricky because we can't graph
that we would otherwise because going through loops doesn't really
through numpy doesn't really work with simpy but simpy has its own
we go it doesn't work with the others but it has its own so from
import plot and so this is the simpy plot and slightly different
here var x y here then this one is similar to what we were doing
that looks pretty similar to what we were just doing same with the
and so this part i'm still going to go through the same thing you
solution get the x solution the y solution and print so this is
what we just did before but what the other things that we can do
that these are equations set equal to zero now simpy syntax for
if i want to get it ready to factor so my y value for the first
so in simpy we're going to define this as an equation first and
that's that first equation and i'm just spelling it out that it
need that so now y first is that set equal to zero and then y1 i'm
which solves that first equation you see y first comma y so i'm
spell it out that it's set equal to zero and then do my algebra
and solve for y and then store it as this variable y1 i'm going to
equation so set it as an equation second the second equation is
i'm going to solve it y second comma y i'm going to solve it for y
i can print them because that might be interesting so it's just
y equals that i will display exactly comma and then here's the
zero again because you know the index of the array so we have
but we were talking about graphing this so let's do that next but
the solution i will display these you know y equals equations and
i didn't just factor it to see that as y equals though that is
that but to plot the solution here see now i'm going to just
as a symbol and then take a look at this i'm going to plot but
is just plot within simp i plot and what am i plotting this y
so there we go so when we factored it into y equals that helped us
but put this into here that this is what i'm plotting these two y
the x value notice also a little bit different the way we display
to 10 i could you know make these other variables but that's going
so then when we run this i see the solution i have it as y equals
and then i see the graph and we see where the solution is negative
so we can do this for you know any other ones here there we go
it negative 2x you know i don't know minus two and maybe this one
x and i don't know like plus eight change it up a little bit and
we'll solve it print out the solution factor it show the y equals
and now we have this new one two six is the solution here are my
two times x plus two and y equals x plus four so we see these two
the two times x has a steeper slope so that's got to be this one
and then x plus four the slope is only one so that's got to be
and we see that they intersect here at two six
all right so we see how we can solve and we can solve and graph
linear equations for equations beyond linear we'll cross that
to be in the upcoming sections now that we've worked through the
now that we've worked through the core skills in this unit let's
and i'm going to work through extra problems using the colab
apply these resources that you're building and use that use these
come up in a textbook or in day-to-day life so we're going to go
here so here again is where we're going to put together all the
learning into your calculator so that you'll have these as a
where you should already have proportions set up so the text to
to enter it in and solve your proportion and remember we made this
that there we go and we already did this converting decimals to
code there and that's also section heading solve for x so each
we're building and then we're going to take like the final product
one if you just have a an equation you want to solve for x pretty
there and factoring so we can solve or we could factor you know
something like that we have we have that and each of these you
because you just have this the solving solving for x we did put a
it's going to prompt for the input and then you see that the
whereas the factoring one it's just this equation that you know
simpy dot factor okay so that's also a section heading then
solving for a variable so not just set solve for x but even if
rewrite it you know like y equals a over b or something like that
numbers this will do that for you and we defined a lot of our
it's not going to be an error to put them in there and not use
what variables you use you can always edit that part and then
the involving numbers or a bunch of letters and variables you know
equal sign and then we have this then we're just going to define
pick what variable you want to solve for set it as an equation
going to solve and this loop runs through all possibilities for s
we have that that we can solve for a variable like again it's
therefore in the table of contents so we're going to add the other
intercept from two points because this in itself is a very common
going to define the two points there we go x you know x and y and
solve for b we're going to get m and b and having those two we're
and then we're going to use that for the graph and you can keep
know you could always change this x min negative 10 and we could
could always change them to 10 in every direction if you wanted to
these you know for the graph and the setup the details could
these and you see for things that we might use we might want to
there so you don't have to really think about you know the exact
this you remember it but it's just there and it's commented out so
and then that way here we just plot the function as a red line so
of these you have a lot of things that are there by default that
you could solve whatever you wanted to solve and graph it so we
section heading then we can double click and remember it's this
because it's in the text not in the code now that became a section
of contents so we have that now the section heading goes all the
bottom so that one we can minimize now this one if we minimize it
document here so besides that i might just want to graph something
this the other code as you're building it remember the slope
then other ways to customize the graph came from some of the extra
in week four where we have you know again all the different things
labels as well as setting the tick marks and this one you know we
here you know and added a remember we customized it and added this
this for yours we're going to put all these as well as the zoom
so this function then does all the graphing and i'm going to skip
the slider remember that interactive plot we're going to run this
we're going to have is to zoom and that's going to be our
hundred that's good and then taking that so whatever that
what we have for our x min and x max and then once we have those
for our np dot linspace to graph and there we go and i just put
two lines as by default you know maybe you want to have two lines
see where they where they intersect so this graphs two different
a linear equation as long as you're using python syntax whatever
i commented this out but again you could have it if you want to
and i just happen to have this one fill between same x values so
y max so that would shade above and it would make it green and the
values from y2 down to y min and make it blue so that would shade
these here in case you need them we're making these default
okay i do want to shade above or below uncomment it and then we
can change now for this one i kept this the tick marks in there
lot of this is based on the zoom so then how many ticks do i want
difference the how you know from x max to x min divided by 20 i
to be a good number to display nicely so we're going to get that
and then cast it as an integer so the number of ticks has to be an
then that way no matter what the zoom is you'll see that we can
grid so this will give us a few things that we can graph you know
given these equations that we have in here a lot of times i like
than just like make that line blank so if you run the code it
something so here we have this graph and we see the default zoom
but i could move this back down and you see everything adjusts the
the graph zooms in and then you can see you know or we could zoom
so yeah pretty good i like kind of for this particular graph i
and then you can see you know about where they where they cross so
want to graph something and there there we have that and there we
and you could have the whole every all the directions don't have
could have that and you could put an html break right after that
words underneath that would not become a part of the heading
but for this we can just put the heading here
here we go i remember there's really no entering we just put it on
somewhere else and now that's also a part of the table of contents
solve and graph a system and this is nice it brings it all
you can put in as long as you have python syntax whatever you have
and second equation and i even have an extra one here just to be
this will even work if you have a square root just to have
the linsolve before to solve uh using simpy the linsolve to solve
is actually another one non-linsolve i like this one because it
in there it can be linear or non-linear it works out so just
mean that you have to have you know something different if one of
but there we go the comments just so you know here's where you
and then you already have the code that you would have copied this
eight uh yeah from from uh the recent week to solve and graph you
tinker with them a little bit you know as we went through and
uh blocks of code you know take the last one that brings it all
over here you know that's what you're doing you're building your
the system of equations and then this will work solve and graph
i just want to show you some of these
so even if it's non-linear and you see it'll give you the solution
solutions notice because we had the uh the loop the four loop here
solutions so it'll have the two solutions then also show the two y
graph them so that's pretty complete that's a good good one you
thing in your toolbox double click and let's make this one a
and i've added one more thing here and we could still make this a
notice this code isn't complete but i put one thing in here they
so you certainly you would recognize that that's import so that
you see this you would also it would be something you already
but notice you have this dot save fig and you're going to give it
notice you have this dot save fig and you're going to give it a
to use notice that'll come before the plt dot show and that
i've tried this if you put this after it actually will save
and what's interesting is this download can come after so that's
that'd be fine too but it can come after because it doesn't
and this is a way to download this to your computer or your phone
because sometimes you might have have something that you wanted to
this and you would put if you wanted to up here you import that
you know you would just do save fig and files download so there we
have all of this and one of the things you can do is in the view
all right and now you have all these in your table of contents and
if you need to there you go you have all the sections collapsed
for x do i need to solve for variable you know i i like i like
and down save graph and download it
there you go because that's what it does is it downloads an image
so already we have so much of the core algebra that you're able to
the code for it and now you have this at the ready so one of the
to quadratics and more complicated graphs we kind of hinted at
if you haven't seen a lot of these and you say oh wow okay now
getting interesting so we'll get into quadratics parabolas you
curve to them and things beyond that so we'll add more to this all
to being able being able to solve a lot of algebra problems in
so when working with word problems not just here's a math formula
problems or some people call them story problems that's when a lot
translating that into a math equation that we can solve so what i
keywords that you can find in the word problems in the sentences
to use and this is not all of them but this is a lot of the main
with this these are the things you're looking for and then after
we'll go through a bunch of examples in the code and how to use
into math equations but let's take a look at these keywords so how
some of the words are going to be if i just actually see plus some
more so if i have something and then i got more how much do i have
money i had increased it might even just be and you know i have
cards how many cards do i have received because a lot of times
up something goes up and a lot of times calculating elevation up
it might even just come up and say added to sum also and sum means
might see some of we might see these you know the sum of three and
plus four so these are some of the ones if you're looking and you
adding okay and a lot of this it's not so exact that you could
find one of these keywords and then automatically translate it to
use a little bit of your human intuition there but it it's very
numbers what which one of these words are around there and that's
of the path operation so let's take a look at subtraction so
minus less anytime i have less than i'm subtracting or it
decreased so i subtract gave because a lot of times things if i
it becomes added to what i have or if i gave then it becomes
down and that also goes again with looking at elevation it might
subtracted and then anytime it says the word difference or i know
between two numbers that's subtraction you know we just find the
be a negative difference might be a positive might be absolute
or if i want to find the difference then i'm going to subtract all
so how do i know that i'm multiplying obviously things are
we want to look for that general trend things are increasing and
since things are increasing you know it's multiplying or adding so
it would be multiplying by just the word by because if i'm
three by five and then i've won't you know also then just seeing
means the area would be three times five of so just the word of is
of something you have the percent and then you multiply times
factor because two things you multiply together are factors times
you know it might just come out and say times and even if it
dimensions and say what's the area and anytime i'm calculating the
so there we go again not this is not all the numbers that lead to
of the main one all right so divide out of so notice of would be
so you know four out of five that would be a fraction four divided
per same actually per pretty much means out of but that's another
of miles per hour i would divide miles divided by hours or
hours quotient we don't see this word that often but that quotient
means that i'm dividing and actually that's the answer when i
you know you know kilometers per hour or something like that but
be some sort of dividing something divided by something else
related to time but it's not always so anytime i have a rate i
and again it might just come out and say divided by so you know
put the word each here because that actually could go for multiply
of it you know if i have if i have 20 students in the class and i
each how many pencils do i need so then that's multiplying because
but if i have if i know how many pencils i have and then you know
and i you know how many can i how many can each of them get you
20 and then i have 20 students how many can each of them get i'm
we have to get the sense of it and dividing like subtraction if i
to be a smaller number then i know it's dividing or subtracting
further you know what's the sense of it am i is it something you
it out among different things or is it just a subtraction okay so
things and the one that carries over a lot is or some version of
equals so that's where we get the equal sign coming into our
then i can translate you know this is was will be something like
so looking at these keywords you know we get the numbers from the
these keywords and we can put together an equation and so i wanted
in the code what we're going to do is we're going to look at a lot
and translating them into math equations and then of course
we want to be able to translate this you know you're not always in
the math problem it's going to be you know some words and we have
problem so let's take a look at how to do this let's let's apply
into math problems all right so let's take a look at the code so
practice some of the math we've been talking about with the linear
especially and some of the python developing equations finding
let's put all this together and use that to solve some problems
can see that y equals mx plus b pattern for a linear equation show
ways you know sometimes we just change out the letters a little
that pattern so if we take a look at number one and this all comes
i have listed as textbook two algebra and trig so you know there
find these because we're just going to pick a few of these and i
you know what we can do with these so if we take a look terry is
terry's elevation e of t that's how i'd write that that's the
um instead of just y equals we'll call it e of t elevation as a
in feet after t seconds is given by this so e of t equals 3000
instead of x we're using t because it's time and we have 3000
e of t that's the function and so we see the slow the intercept
she terry begins at 3000 feet up and then goes down the slope at
that that is the slope the slope of our equation on the slope and
is going down there we go so we can see the slope we can see where
um and there we go just uh finding that slope we just look at it
now we have jessica walking home from a friend's house after two
12 minutes after leaving she's 0.9 miles from home what's her rate
miles per hour well right here we have distances in miles but the
so if the question asks for miles per hour we definitely see also
have a time and a distance and then another time and distance so
distance and having these two points we can go to our calculator
something that you've already created you know remember we might
calculator and then hopefully you know then you would have created
for the different things that we want to be able to do and we can
equation from two points because even though the that question
and everything we're going to do more but the first thing it's
for us and hopefully you know that's it you know we have these
make use of it so you would have had all this and then we would
is 1.4 but that x value it's two minutes and we have to remember
it's two minutes and there's 60 minutes in an hour so it's two out
this if you want but you don't even have to python will take care
steps and the y value 1.4 miles so the second x value 12 minutes
an hour so it's 12 out of 60 again that reduces but you don't you
0.9 so having all this you can just put in these four values here
we'll print that out so you see the equation and then we'll also
what the question is but this will give you an idea of some things
this and all we needed to do is recognize what these values were
run it all right so this i absolutely would take this slope as
python calculates things it might be this 0.9999 it's three and if
you know you could always go back and put a round function in in
with this you could always round it to two decimal place to one
but either way we see that remember our first point was two
zero at two minutes she was 1.4 miles from home but at time zero
1.49 or 1.5 it might round so we get our values here and you know
function in there but i'm not worried about that right now and
but it's still ran occasionally that happens just the the way it
some things you know we get a warning you know some value maybe
what we were working on gives us this warning but it's still ran
and then we also have this graphed now if we have you know the x
so this is her time from home
so this y value notice it seems like this graph is completely
only goes down to net 9.6 we want it down to zero and then we have
know what's that all about so remember mathematically a lot you
these values exist you know we make this equation here negative 3x
but that whole equation exists so we can actually change the graph
you know later on in this document is you know we can graph you
but we can just change the graph here and our x minimum if x is
because negative time you know she was still at her friend's house
the walking and the x maximum i mean we can really zoom in now
going three miles an hour and she only had half a mile to go like
small i don't know i'll maybe i'll just reduce it to five for this
um is zero and the y maximum i don't even need that to be 10 i can
it five but we don't even need to that much we can really zoom in
short distance all right so now when we have this now we have
you know this is the only part we needed so we could look at this
a half miles away and so therefore you know she's walking about
about a half hour to get home and there we go we see you know the
whole equation we see the graph and then we can graph the the trip
know change these you know if you really needed to explain this
always put you know x values you could change that to time y value
there we go so we have these calculators that you know we're
about it here a lot now but if you had this at the ready you might
just you know see this oh i see my two values plug them in click
you know move on in a few seconds here so some things we can do
similar and maybe we'll do number three you know a lot quicker a
marina sailing directly at it at 10 miles per hour so now we
because it's a hundred miles away so that's where we begin at 10
the distance from the marina then it's a negative 10 100 minus 10
that's the equation 100 minus 10 x and we could always go to
and see you know just the trend how long does how long will it
marina there you go 10 miles an hour you might even be able to do
10 hours to get there and that's the thing we have the setup for
difficult but sometimes you can just calculate it yourself all
these and remember a linear function we'll get into the other
beyond that but a linear function has no exponents so there we go
linear seven is linear eight is not because we have x squared nine
squared nine is linear ten is not we have x squared eleven we have
not even a function like the ones we've been doing so that's
function like the ones we've been doing and certainly not linear
denominator then that would not be linear but with just a five in
so there we go and increasing or decreasing we would just look at
positive it's increasing if the slope is negative it's decreasing
coefficient so slopes four it's increasing 15 slope is five it's
and 16 the slope is negative two so it's decreasing 17 it's
that and just like we were doing with these other problems you
could just plug these in two four four ten there you go run it and
equation and see the graph so a lot of these you know once you
becomes a lot easier there you go same thing a line if we have two
in there all right now let's take a look at 37 so these two lines
of equations are they parallel perpendicular or neither well one
we can look at one of our other notebook sections and we can graph
a look at this 4x minus 7y equals 10 so let's take a look at this
how about this graph lines and zoom in or out remember you would
too and we defined our function so that we can zoom in or out and
i could just graph this now also so one of the things we can do to
if you wanted to is put it and this would be something that you
of these in the y equals version because they're not in y equals
to graph you see it's it's going to be y equals and they are going
well let's go to another one solve and graph a system because this
equal to y in fact we just make it equal to zero so i actually
four four times x minus seven times y and the only thing we need
that equals ten subtract ten from both sides you see much quicker
second one seven x plus four y equals one just subtract one from
have here so it underlines these but the moments we run it'll be
well because as long as you have to set equal to zero just
over and remember you would have already made this hopefully and
your second set equal to zero and remember we're solve then we
solution and then we're going to also convert it to y equals here
and then graph it print the y equals version
and when we run it we see we have the solution and it's not even
than the question asked but if we already had the code you know we
and yes these are two very weird fractions that you know it would
were calculating this by hand we get the solution and so we also
or perpendicular and we see where they intersect at this value
almost negative one little bit off and then a fraction there and
four times x over seven minus ten over seven so we see this one
and this one has a slope of negative seven over four oh then they
what this graph shows so let's try to change this because the
even though we're multiplying by x that coefficient is four over
seven over four and that's what makes them perpendicular the
seven negative seven over four that if you multiplied them
change the scale on this we can probably it'll probably look more
so this just naturally scales it this way all right so we have but
in this same window the y value goes up to 15
so the you know it perpendicular this intersection would be at a
and the you know we just can't see that right angle because of the
all right so that work i would work for any of these now you know
just add y to both sides you know subtract 12 on the first one and
and we can use that same thing same with 39 maybe we'll do another
yeah if we have this let's just do yeah we'll do one more here
so if we go back to this then i'll make the first equation then
y plus x minus 12 because that i would have to equal zero three
have to put the three times y whereas algebra you won't see that
so three three y plus x minus 12 equals zero and then on the
y so on the second equation we'll have eight x
eight x eight times x plus one plus y and see i don't even for
you know for other ones you don't have to worry about factoring it
zero we will get the solution and then we're going to show the y
so yep these do have a solution where a point where they intersect
perpendicular because the slope is negative one third you know one
slope is negative eight so a steep slope at negative eight and
not as steep so they will meet at this point there we go so pretty
system of equations solving it factoring it graphing it remember
you don't build these calculators for yourself then you have it
some other things and so we see you know the similar things lines
in any of these you could build for yourself you know a notebook
do this for two for two point uh two lines or you could actually
and you could use the slope intercept equation for the one line
later and then you could use the slope intercept equation again
it in so that's what we have here like this one you know you have
always could then take it and you know copy that and write it in
and do the other one copy it as line two so that you know that
do if you wanted to you know take take something like that and
one but nonetheless you know right now as i have it it was it was
get the equation and you could if you wanted to copy it into the
so all these yep same thing two points you get the equation two
and there we go just looking at that equation you know parallel
perpendicular then you could multiply the slopes together to get
and neither is anything else as long as they have different slopes
things you can calculate and i'll leave this to you if you want to
practice some of these see some of these you don't have to have
or you don't have to have the the note jupiter notebook or co-lab
pattern that slope intercept equation here what's the y-intercept
for this particular one you can actually count you know oh wow
five over four so the slope would be negative five over four so it
y equals negative five over four x plus five or if you wanted to
and plug you know go back to the notebook plug them in and see it
see that that'll work for any of these you know having this you
so b is one and then from that to the next nice point it looks
three there you go there's your slope so you can you know work on
so some of these again any of these you want to see a graph
we could just plug any of these into that other notebook section
the graph all right sketch a line
good and again you can practice all these if you want the tables
so really just remember x and then whatever you want to call it g
and so if i want the equation then what we want is we can just
so that's you know x is zero y is five and the next one x is five
and we can get that equation but then also if you wanted to you
and see if it's the same slope so that's how we would determine if
always just plot any of these points and and see what it comes out
just plot these points as their own array and see if it looks like
another interesting way to do it and there we go so so yeah let me
that on on one of these and so if the x values are 0 5 10 and 15
in one of these where you're going to graph so if we have
yeah here and we'll even keep the zoom in so one of these where
we have all this for the zoom but what you can do is you could
all right so we could get x equals and make it you know 0 comma 5
and we can just make that the array 10 15 and then
and then you could now we could just comment out all of this
and take this and this first one we could put you know comment out
and we could have y1 and put your y values 5 negative 10 negative
negative 25 negative 40 so remember that you know that that numpy
of values and we could just put our own array and if you wanted to
you know make them make them dots i'll say ro so we'll make them
for the points so we could have the x array have the y array and
there we go we just commented all these out and
so we have this looks to be that they're in line and we can change
you know yep it definitely looks like they're in a line
so we could you know there we go we could say that yep that's that
works that is linear so some some of these you might just notice
in in that table but also i wanted to show you for this or for
in in that table but also i wanted to show you for this or for you
to do for that little question but also just showing you what you
more complicated sets because all of these that you know this this
and just a few values just to show you but remember this is this
toward data science if you want to continue following this path
four values you might have like you know four thousand and so we
do this we'll have other ways rather than having to you know write
those values if there was like a thousand of them and then store
other y values but then you know can i do this can i just take
what it looks like now these are the things we want to be able to
some some things you know and and it answers a very simple
because otherwise you know they might get some of these that the
could not say that they're they all line up nicely so that's it
know missing values of a linear function and remember you can
a table of values too if you wanted to so you know those are some
we would have to put the slope formula so remember the slope
looking at the code you know find the equation of the line goes to
at the code the y values b plus one and then the other y values b
up one you see the y value went from b to b plus one but then look
didn't change so a minus a is zero so we have it's actually not a
x value x equals a so these are some of the things just you know
the slope and you could always do some of this with you could
if you look at the the other one that we were doing here solve and
have to comment out the graph probably wouldn't do too well but
you know you if you define more variables you could still take
again the solution might not be uh really possible but you could
actually solve and this solves it for zero but you could actually
for y or whatever value you want so simpy will do that for you so
you could have a make another section in your notebook that just
factoring all right so there we go and so we have some other ones
now this we have at noon the barista knows she has twenty dollars
average of fifty cents more from each customer so remember that's
customers tipping more some tipping less and then it averages out
because we would right away see the equation we begin with 20 and
because we know she's getting something more 50 cents from each
so we see that equation then we you know right away we have that
and we can do something with that we could like graph it we could
this particular question we just says n more
so it would be 20 plus 0.5 n you know we just change that variable
she can plug in a number for n figure out you know how many tips
and this 115 these are some of the things that you know you can
a gym membership with two personal training sessions and a gym
training sessions cost 125 while gym membership with five personal
what's the cost per session so we take it as the membership itself
and then you could have like you know each of these so really we
many training sessions and then the y value would be the cost and
we don't it's not asking us to graph we absolutely could go back
and then five sessions was 260 so we could go back to this and
you know slope intercept from two points and we could say you know
cost 125 you know how many sessions and then dollar amount and
would be then 260 and oh now this we need to change this the x
fine for five but let's take a look at this and let's see what we
go up to 10 y minimum zero is probably fine but the y maximum and
like you know 500 we're going to go beyond that but that's fine
can see that we're going to go beyond that we're going to go
that but that's fine and when we see the graph so we see the
itself must be 35 dollars and each session must be 45 dollars and
there we go you know and we see where we see the cost 45 you know
and then we see the increase okay if somebody wants to plan you
how many training sessions do i want maybe this is in a month the
it might be about eight in a month and can calculate oh there we
that'd be four hundred dollars or you know do i want to just try
and not get any training sessions and you know there we go then
at the zero value and that's what we want we want to you know use
some different things you know the cost like 116 here so the
there's a linear relationship between the number of shirts it can
price p that it can charge for sure so there you go selling and
and this is you know things that people want to find out because
what price you know they definitely start out like can't you know
have to make money i can't lose money but then beyond that we see
different prices are possible so somebody says that finds this
from somewhere else some other people selling shirts oh okay i can
if the price is thirty dollars but three thousand shirts if the
so there we go again that classic y equals mx plus b but we just
change the letters p of n you know the price based on n shirt n
there we go we can we can look at this you know n shirts now
i might take that the price is the independent variable because
you can buy and so we might you know do something like that and
units here we'll get into other things where we can then based on
we can find that that you know that equation for price and then
it a step further and say what would be my profit because just as
so a thousand shirts at thirty dollars so it'd be thirty thousand
shirts thirty dollars each but three thousand shirts at twenty two
thousand is forty four uh uh sixty six thousand dollars so just
selling more shirts but the price that it had to lower or reduce
much different and so it sells three thousand shirts so instead of
sixty six thousand dollars look at that almost uh more than twice
less and some people who don't look at the math of this would say
you know reducing it eight dollars is that going to double my
the revenue we don't know the cost of making the shirts but it
just lowering that a little bit because it reached so many people
and so that's what people are looking at you know and in again in
math behind you know how to how to get this how to find that
value and you know what you know what are we looking at here how
you know ideal shirt price so there we go there we go all these
equation we're trying to maximize things if we look at number 18 a
relationship between the number of bean stalks she uh she plants
that each plant produces so 30 stalks each plant yield you know
so 30 stocks each plant yields 30 ounces of beans but then 34
beans you know they're all competing for some of the same
you know they're all competing for some of the same resources so
equation and then we can try to find so what would be the maximum
what would maximize the bean yield so you know it'd be really
um yes so notice this uh and the yield would be 30 ounces that
30 stocks times 30 ounces see then 30 times 30 so that's 900 or
and i'm not going to do that in my head but we can see some
these in some of the other business applications later on so some
population and like number 120 drawing linearly we can write an
another one where we often do this all the time converting
and we have these two values zero degrees celsius is 32 degrees
100 degrees celsius is when water boils and the corresponding temp
can do is we could just take these now we could also use this to
but we could also take this you know slope intercept from an
there we go still better sub equation from two points and
we can say all right so we have zero and then 32
and celsius would be 100 and fahrenheit would be 212
here we go and see the see the graph
now the graph in this case okay and i'm not even worried about
the main thing we wanted was this equation here 1.8 x minus 32
fraction that's nine over five so there we go that's and remember
the x value was celsius so that's how we can convert celsius to
and so if we look at the increase you know 1.8 is almost two so
degree increases almost two degrees fahrenheit increase so we can
so if we take a look at this you know we you could always you can
another function for yourself that you could you know you could
celsius to fahrenheit fahrenheit to celsius you know that make
you know put a heading to it because remember as soon as you have
because we're not in the code but if it's in there then it becomes
of contents so you can always make some of these things for
want to give you some of these practice problems you know if some
want to combine some of the things you know you have room to
so there we go and then once you have that equation you can find
that function of 28 degrees what's that become in celsius or
uh that's a good one because negative 40 celsius is negative 40
they actually agree it's got to be really cold but when it's that
having a thermometer would probably agree too yes it's cold so
some of some of these and hopefully this is you know find this
interpret some of the word problems and use some of the notebooks
solve problems answer questions and yeah you can continue you know
know make make it your calculator anytime you have different
might be useful make a function pick a formula another notebook
on to the next thing now that we've worked through the core skills
some extra problems and i'm going to work through extra problems
see how you can apply these resources that you're building and use
come up in a textbook or in day-to-day life so we're going to go
here for these extra problems we're going to look at just ways to
you have different situations word problems how can we decode
then use python to solve them so just here's some examples and all
first textbook you have the link so let's look at number 10 on
canadians work 39.5 hours per week so if the typical adult
what's the percentage of hours in a single week left over for
so we need a few things here 30 so we need the number of hours in
even just going through your python colab notebook we have all
i'm going to click on solve and graph which we're not doing yet
the blank you know line of code here and even in the print
first of all we can have the number of hours per week and that
and then if we want to look at the number of hours that canadians
from that and python knows the word of operation so i can just put
you really don't need it 39.5 so there we go uh 24 hours a day
and then we actually can also subtract eight hours a day eight
times seven so we have how many total hours in the week and then
the sleep hours again all this in in python shift enter and we
72.5 hours is you know and it works out look at look at that you
of time to go out and do things and we can do all this just know
step you can break this up into different steps and put variables
this all right and let's take a look at another one that number 14
for the first half of 20 2009 we're down 46.733 percent we'll talk
second from 2008 when 1500 new homes were started so from 2008 to
would be that times one or times 100 which would be times 1.00 so
that times one but then since it went down we want to think one
percent it's the 100 minus this 46.733 and then the original was
so we can just go right back to this and we have 1500 new homes
46.733 as a decimal is going to be 0.46733 and you see that we
so one or you know 100 i mean it's not going to mess up the code
but so you know that's 100 so if it was that 1500 times one that
year and since it went down it's times one minus this rate you
and these are number of homes so we're going to round it down and
you know that 0.005 is you know i don't know that's what five
know they put a few boards there or something on the lot said i
going to call it 799 and that's how we get this times you know one
went down and in later weeks we're going to talk a lot more about
so this is not the only time you're going to see this and in that
these other percent increase or decrease but on page 73 i want to
so if 999 changed to 1049 so the amount of change we would just
and we see you know we can do that you can do that in your head
but then the percent changes we take that difference over the
so if it started at 999 that's the that's the difference so that's
and again we can look at percent change so that 50 cents 0.50
so that's we get that difference divided by the original number
we're going to multiply it by 100 because it's the first two
the next number is a zero so it's really a five percent change
it to sometimes people like to put that into the formula times 100
there we go as a percent I mean if it's just for your own
make it fancier if you're doing this to explain you know costs and
business proposal yeah it's nice to have the extra bit you know
people can see oh this is exactly what you're talking about for
put it all in the print statement and you know see see the output
1999 lowered by 10 percent so we're looking at these keywords
we need that formula one minus the rate again might be new to
we're going to talk a lot more about it in later weeks but 1999
we're not decreasing by an amount so we're not subtracting
one minus three and I can even you know convert this as I'll just
10 remember 0.10 so I put that in there with the extra zeros but
get this one minus three if it didn't change it would be that
one but it's times one minus three and then that's the new number
any practical connection it was just what's the number if it's a
to two decimal places it's 17.99 so that'd be something like you
1999 and it was on 10 off so you end up paying 17.99 and knowing
you have calculator so you can do this you know right there on
this app you can set up different things for percent increase and
in the store oh what would the actual price be and at that point
we go and here we have this what about when increased by 40 is
before I even get to what we're going to calculate I'm going to
because I don't want the code I just want to show you the math of
I'm going to call x increased by 40 percent so if it increased
and then that would equal that new amount
so you know the the beginning amount or you know x or we can call
times one plus the rate equals the new amount and I just put this
just looking at this formula and so if I have this
then the question is what amount number six here what amount when
so that would be x times and when it's one plus three that makes
point four I put the zero if I wanted to equals 3500 because one
and then in doing this we remember solving for x I'm multiplying
the print statement I'm doing this 3500 divided by 1.4 and we see
you could write your math in here some notes for yourself the
plug in the numbers so then we see what's the actual math that
oh dividing by 1.4 so we'll do that and that's the one thing that
others are comments there you go 2500 so we have some of these all
I actually want to skip over to this baseball one I skipped over
are more straightforward now let's take a look at making use of
this notebook for yourself let's make use of the system of
15 the local baseball team sells tickets with two price zones
to third are priced at twenty dollars per ticket all the other
dollars a ticket and last night's game 5332 fans were in
worth 71,000 how many tickets were in each zone so let's call x
those the twenty dollar tickets and let's call y the ones that are
things we want we want to know how many tickets in each zone so
so twenty dollars for the good tickets ten dollars for the lower
seventy one thousand seven fifty so if we go to our solvent graph
you might have your table of contents jump right to it solvent
and y and you can even write some more stuff in here and you know
a look at this if our two equations are twenty dollars times x
times y how many of those tickets did we sell equals that total
sure we get it exact seventy one thousand seven fifty so now we
twenty dollars times this many tickets the good tickets plus ten
that are further out equals this how much this much money that but
i want to solve this i need another equation so what about that
three hundred thirty two fans were in attendance so x and y were
section so x plus y must equal five thousand three hundred thirty
in the way we have this set up here we can just set this equal to
equation and we're just going to put this twenty times x plus ten
x plus ten times y and then equal to zero i just subtract that
and then that would be that equal to zero
all right and the second equation set equal to zero so x plus y so
five three three two that would make that set equal to zero and
other things here if you want to factor and then just setting up
way to set it up because remember we already set this up to solve
and the graph you know just might help visualize it and when we
see the solution here and 1843 and 3489 so that's how many of each
because when we add these up then that's going to be five three
we know how many of each each ticket so 1843 people sat you know
and 3489 as we expect that's there's more room out there in the
that's how many people sat out there and now and now we can figure
and we see the graph just to see the comparison here
so pretty cool we can we can figure out given this information
how many people sat in each place and who knows maybe if it wasn't
breakdown all right and you know some other applications we'll
increase maybe we'll take a look at this one here so number 15
for her trail mix recipe let's talk about but the by weight her
30 percent cheerios 20 peanuts and she wants to make two kilograms
just calculate how much of each she's mixing so pretzels cheerios
we could just go right to right to here and before i even get to a
we could just define some variables in python we like to use the
pretzel weight maybe we'll do pretzel uh pretzel there we go
times two because it was 50 percent pretzels and she wants to make
going to be 30 percent and peanuts 20 percent so cheerios equals
uh peanuts equals 0.2 times two now we have now we're going to we
each of these and you can put comments in there for yourself if
uh talk about the cost so there we go if we have the the cost so
9.999 and so if we have this our cost equals pretzel times 9.99
kilograms at 9.99 a kilogram plus and we'll look at cheerios 6.99
so now we have the total cost here and that should be then the
fine but the question then asks what's the average cost per 100
so 100 grams compared to two kilograms is divided by 20 and we
to also bring it up to the proportion earlier on in this notebook
kilograms 100 grams and so it's we can just put this in the print
because that's the cost for 100 grams there we go so how many of
but then the final question uh we need to divide it by 20 we only
100 grams and there we go 80 cents
which makes sense because if we take a look at the total cost for
yeah when we when we're buying this full two kilograms you know
16 dollars worth of trail mix i mean you know hopefully two
it'll last a while so she just wants to make 100 grams so that's
100 grams you know so that people can eat it before it goes stale
there you go 80 cents all right not bad so some other things that
making use of these calculators that we have we can take a look at
options for things like green energy and so i i put in here you
one thing you know one thing and it was i think i did one solar
you know you want to buy this you know live live off the grid or
for somewhere so here's a solar panel charges up a battery and the
and then the output is 110 watt hours now 111 so you can certainly
possible that's just you know that output i normally would then
111 watts for an hour and 111 watts that should be enough to
charge a phone few light bulbs also so you know that's something
make use of 111 watts like i said laptop charge phone power a few
and then that way so what what this would be is so the uh
hours because we use so much and that's like 15 cents i think is
so 111 watts that's you know 10 of that a little bit less so yes
you know this 111 watt hours and i was thinking you use 111 watts
a 1.5 cents okay now beyond the savings if you're also doing this
grid or you know uh you want to run run some stuff like out in the
really plug it in well that's the value of this but let's just say
electricity cost so you know that 245 dollars and if you run this
all you're making full use of all this for an hour then it'd be 16
um rough estimate you know doing a little bit of rounding here
you know a little bit less than three years and if you do that you
in a thousand days which for a lot of investments that's not that
and then after that free electricity you know you paid for this
you're saving this money for the thousand thousand days and then
already saved enough money to pay for it and you get the free
another comparison so this wind turbine i find all these nice you
isn't it you know it's kind of interesting so uh did that not
wind turbine that can handle like low winds and it's rated for you
the idea is that if it's low wind it might be a whole lot less and
you know it can say 2.5 meters per second low wind speed which
and even at that point it'll turn it'll generate some electricity
like this and this one was 270 dollars 400 watts but low low wind
okay so let's just say you can generate 40 watts for 24 hours
not dependent on the sun you know you could have wind blowing
kilowatt per day 40 watts it'd be like you know 960 watts we'll
just an estimate anyway so that one kilowatt hour you know on
so if you have it somewhere where it's low wind there we go that
gives you how many days 1800 days so this one would be if it was
five years to pay for itself and then after that you know free
not so bad as a return on your investment but i just happen to
a windy area and let's say you can produce a constant 400 watts
places you know especially if you're near like a body of water
wide river you could definitely get a consistent wind and if
and it would only take about half a year to pay for itself because
watts that's 9.6 kilowatt hours per day or dollar 44 and then just
divided by a dollar 44 187 days you know just over half a year and
space hey by three of them and because you're making you know
uh three of them is probably enough to power you know somebody's
you know you're you're you're saying you would be saving all that
of the three of them and power the whole house yeah about six
that it would be that about that same yeah so really interesting
you can do these calculations i just wrote them here but you can
co-lab and do these different calculations graph different things
that that that's the idea with having all all you know all the
fingertips you can count you can calculate things and figure out
spend this much money and then you know generate this for
say it's not a priority right now and you know that's it but you
numbers so that's that's really some of the some of the uses of of
and you know also making use of you know the co-lab
uh graphing some different things or solving some problems so
and hopefully this gives you ideas of other things you can do once
notebooks and you have the ability to calculate and graph some
use of it to see what you can do to make money or save yourself
the next unit then so let's talk about quadratics so the word quad
why would we have you know quad square but then it's and we call
two so where does the square come from the square in quadratics
so where does the square come from the square in quadratics comes
to the original algebra back with al-khorizmi so the if i have a
each side i'm just going to call them x but then the area of that
be x squared and that's where that's really where this notion of
actually tied to physical area the area of a square but there's a
and this comes up so often that we get beyond even the the actual
this for a lot of other things so we look at the our equation y
graph this and when we get into the code we're going to get into
look at some of those applications too but when i'm going when i
quadratic it's going to be a parabola and you know it'll probably
than that but it'll be a parabola so that means you know and if we
values for x give me you know i square them and give me some y
when i square that negative times the negative makes it a positive
around and so you know we keep going up and then these two ends go
but yeah the the negative x values get squared so then the y
i still can get negative y values because if in my graph i
subtract you know five or something like that so there's
squared are less than five so when i subtract i get a negative y
but you see the the general trend of the parabola here and they
but if you have if you have a negative x value
you so any negative x value it looks like a frown so our
be negative so let's yeah let's take a look at this if i had any
quadratic and this is the general form so if i have the general
y equals ax squared plus bx plus c and that covers all the
any quadratic equation so a would be my coefficient for the x
be my coefficient for the x term and then c would be the constant
a has a number then i can have a quadratic b and c can be zero
oh well there's no x term b is zero c was zero and then the other
five so then c would be minus five b would still be zero so there
any quadratic and as long as a has a number to it then it's a
then it's some some other type so if we take a look at this and
down like a frown a is positive opens up like a smile and the
is they're all symmetrical so the vertex is the point at the
how it turns up of where the gravel turns around so since it's
is going to be this definite formula negative b over 2a so what i
i can plug in my four my values for a and b and get the x value
the x value i would plug that x value in to get the y value and
that would be the point that if i had my parabola that would be
it turns around and also just looking at that x value remember
divide the parabola nicely so we're going to look at doing this in
and then finding the vertex finding a lot of other things so we're
be able to do that so i'm not going to worry about all the
you is one other thing that we're also going to look at the code
this formula is a lot of times when i graph this if i were to
my x y and you know let's say i have a parabola there i might also
where does the parabola cross the x-axis and so when it crosses
because you know on the axis i'm not going up or down at all so if
would talk about solving for x but if i have something like this
i have one variable which is x how would i solve it we approach it
than we would the other the other ones because when i square root
to happen as a part of the process when i square root something
positive or negative possibilities because if i had if i had the
four and then the square root that it's positive four or negative
positive two because if i had two squared that equals four but if
that would also equal positive four so if i'm going the other way
square rooting yes it could be positive two or it could have been
finding the roots for a quadratic you know setting this equal to
involve square rooting which gives me a possibility of a positive
where we have you know our two possible answers and so that's how
quadratics you know the way they cross they're going to cross the
to find the roots i want to find out those two values and the
so again knowing a b and c the quadratic formula
all right so and notice it's that
that vertex plus or minus something and then that's how we use
b squared minus four a c all over two a again so this is the
because i have plus or minus it will give it will give me two
the code we would run through this once for plus get that answer
there we go but also since i'm square rooting something we're just
the real numbers here and if i have a negative value under this
solution so you know we could get into imaginary numbers and you
why should we let that stop us but for our purposes we're not
we're going to say that if it's negative then there's no real
just stop there so in doing this i would often test this we call
discriminant and i would often test this you know b squared minus
actually that can be zero which is fine because that'd be plus or
it would have one root it would just touch the x-axis that's fine
means i have no roots and i would have a parabola that just never
that's perfectly fine it's possible and in that case i would test
then that would save me some time you know not having to do all
this old school and just factored it all out you know right right
it takes a while we're going to look at how to make this a lot
we're going to put these formulas in and then we're going to find
oh you know maybe we'll even graph them too so this is the formula
they're both had the same denominator so i could i could make this
you know do the adding or subtracting in the numerator all over
and mathematically that works out you know it's another way to
this is the quadratic formula as we would often see it just like
all over 2a and so for as complex as this could be there's only a
i get a b and c formula for the vertex formula for the roots we
we'll you know then we can look at some of the applications but
the essence of looking at quadratics here and so now let's take a
um well you know how to solve these formulas and everything so
so solving a quadratic equation is much easier with code because
talking about that we would work out by hand we're just going to
so you can just define a b and c once and then run those values
and output your answer roots vertex and whatever else you need so
that work out uh nicely a b and c and what do we want to do let's
so we'll print out what our function is then we'll calculate the
variable and that's the negative b over 2a that's going to
no order of operations but this 2a does need to be in parentheses
so we get that x value and then we're going to take that x value
for the y value a times and my x value vx and then square it plus
so i get i plug all that in get the y value and just like before
there we go we just print the equation now we have the vertex as a
and we'll go on to the roots and the roots remember the quadratic
but it's actually d is for determinant here that's the part that's
because if that's negative then i won't have any real roots and so
under the square root b squared minus 4ac and then i'll test it
zero because if it's not then i'm going to print out no real roots
than or equal to then we're going to calculate the roots and
quadratic formula so since i already figured out d i'll make use
so we're going to run through this twice for the first root
and then all that's over 2a and notice parentheses for the
and then the second root negative b minus the square root of d and
so i'll print this out calculate the roots print it out or you
and there we go so i actually already ran this and what do we have
x2 plus 5x plus 6 and then we have the vertex is this negative 2.5
and then the roots x equals 2 negative 2 and x equals negative 3
so there we go if all you need to do is solve it it's nice to have
just change a b and c and run it again so if we want to graph it
do everything we were doing plus the graphing part remember our
numpy i'm also going to import math for some things that we'll do
i just pick different numbers here and i'm going to print out a b
i'm going to print this out calculate the vertex print that out
so notice i didn't do the roots yet and we just have x min x max
else we were doing for graphing define the x values set up the
parabola i just called it y1 even though i probably won't have a
ax squared plus bx plus c there we go i'm going to graph that
so i'm going to plot x and y1 then i'm going to plot the vertex as
here for the the plotting parabola the vertex point and then
it's going to be a line and here i'm defining two arrays each of
that's going to be a red dot so then we're going to find and plot
doing with calculating the roots from before but i'm going to add
and once i get the plot i'm going to plot root one root one zero
you know the array of my x values and then the y values and this
so that's why it's good so it's going to be a green circle so i'm
i'm also going to print out the roots because i want to see that
it'll have your equation here there you go x squared plus four x
and give you the roots now these roots are irrational you know
wacky decimal we could you know do quite a few more lines of code
wacky radical answer but we're not going to worry about that now
if you're writing this down somewhere you might round it to a
but here we go we plot the vertex as a red dot the roots as green
the x-axis and then we graph the parabola and so i can redo this
that we were doing before one five there we go six and that's all
and it'll run through and calculate all this there we go x squared
and here's the vertex negative two point five negative point two
two and negative two and negative three there we go now there we
where it crosses the x-axis and see the y value of that vertex is
two five so it's just below it but just barely and there we go so
we can graph it we can get our roots in our vertex and for most
quadratics that's what you want to do so let's take a look at how
graph so i'm going to show you some sliders here and that's going
other notebooks so how a b and c so the first thing is we're going
map plot live in line and we're going to write that first and then
widgets and interactive the same and then the same other things
so the way that these widgets work is we're going to put all the
we're going to connect again with functions here i still defined
later on i wanted that to be a short name for that line but you'll
this f but it's the function of a b and c i'm going to take those
now you could always make this say quadratic and you know do
with the quadratic roots vertex we could actually take everything
with the plotting and with solving and put all that in this
it more than just that if i might say quadratic and take the
you need so kind of cool that you can do that but here we're just
so my function there we go x min x max all those i'm going to
remember a b and c would be the input so we would have those and
plot the the parabola plot uh the vertex as a point plot the roots
there we go this all of this here is really just extra for the
title of the graph i did that instead of printing it out which i
could have done but i wanted to show you we could set it as the
needs to be a string so here i'm going to take a b and c and
i'm going to take all of this and i was you know this doesn't
but i was thinking of that h1 for the heading so i'm just going to
all these that exact y equals combined with sa that string and i'm
as h1 but if i just leave it at that it'll still display in a
like extra quotes and i don't like that so i'm going to just find
it's just blank with quotes and that's going to be a string and
for w in h1 you know w like for word in h1 and then h2 equals h2
these two strings put it all together as h1 but then i still
this way combining these now h2 is a nice unified string without a
you know again it's a lot to just it all leads up to the sake of
as the title okay and you know we'll see hopefully you know it
that was you say oh that was worth it all right so here's where
this interactive plot now that's just the variable that i chose
really happening this interactive function so if we take a look at
so that's where the name of your function goes and that's where
i wanted this to be short so i just that's why i called it f so it
that function and then it defines a with a range from one to nine
to nine and c also with a range from negative nine to nine a i
was zero that's actually not a quadratic and i want to illustrate
at one so we just define this interactive plot and then notice
then if i just say interactive plot it's going to print it's going
so we'll see this interactive how that makes the sliders here
there we go and it default shows them in the middle and see this
that when it starts out you see the title of the graph y equals
zero you see that's it just and if i go if i make that down to one
basic parabola you know x squared and i don't have to put the plus
going to write that every time and then we can see what happens if
i can move c and it'll adjust the graph it'll adjust the title
of the graph there we go and then we can see what happens if i
b you see it moves it along here and now
it got to this point that now where it is i do have roots in the
and then if i have i can see where b as i move that around
affects this whole graph and i can see then how a affects the
so we see some different things that we can do and all these are
you can tinker with these but this is all you know it was just i
that you can set up sliders and in this case to display the
display the graph see the roots in the vertex
you see and i move that down so we display the graph see the roots
with sliders you can see how a b and c affect the graph so knowing
this code at your disposal you can really see you know most
do with quadratics you know find the roots in the vertex see the
you know do some other things so there we go this and some
um now that we've worked through the core skills in this unit
and i'm going to work through extra problems using the colab
apply these resources that you're building and use that use these
come up in a textbook or in day-to-day life so we're going to go
here so here we're going to walk through the foundational math
have not already done it please give this a try on your own this
done that and you're stuck or if you just had a question about one
hopefully answer all those and just like the other certifications
and put this in your uh in your google drive so you know file save
and this one we're going to focus on building cartesian graphs so
deal with graphing we're going to look at some different functions
so you make a copy in your google drive it might be in your google
you can put it wherever you want and now hopefully you know i
you're now working from your copy and we need to acquire the
write just like the certification one the code do you write when
it'll run through these tests to see if the code is what it's
some feedback so this first cell you don't need to do anything and
what you need to do here for future reference in case you want to
you know you include in your colab notebook so this custom library
code is going to get that and save it here in a work in a local
need to run this for each new session as i mentioned before it'll
because of an activity after 30 minutes at the most or even if
out so each new session run this and it'll go through and then
to run yep and see just a few seconds code test passed so there we
so let's take a look at some coordinates here cartesian
renee decart because that's part of his name cart and you know
in life when your last name becomes an adjective so he among other
coordinate system that we're familiar with with zero zero in the
horizontally positive to the right negative to the left and y
down so then each x y coordinate tells you you know how much
going up and we can plot all these points our go-to library is
and as we were talking about importing your own personal library
to do that in a little bit different ways a few more lines but a
uh i say commonly you know reasonably used i've been around a
google colab already did that install part so you just need to
we have that nice benefit you know things just work in the google
and we're importing this library yeah that's a mouthful so we're
that way every time i reference it plt.plt. i don't have to
okay so this is going to be the first thing is the basic just
you probably could change these variables but i don't this is
in the documentation for matplot library so i keep these and it
assigning two different variables to this but it's you could have
going to worry about that right here but you could have multiple
could have like nine little graphs in it if you wanted or
would put numbers in there but we're not worried about that now
exists and then plt.show that's always going to be our last thing
you run it and there's our basic graph notice we didn't add
so there's not nothing going on here and zero zero instead of
bottom left because we're just showing the positive quadrant here
values up to one positive y values up to one and that's it and
test and yes code test passed if you click the button correctly
so we'll go to step two all right so now we have the standard
axis and we're still going to go through import this establish
something here so this gives us the size of the graph and i just
this would be better we're going to modify this as we go on but
that'll give us the size of the graph 10 in every direction so
so you see it does give us 10 in the direction and if you follow
the zero zero exists in the middle here even if you don't see the
positive to the right up to 10 negative to the left down to
in the middle positive up to 10 negative down to negative 10 so
here somewhere all right and this one was one of these that i ask
rerun so it's run this to see what it looks like then change the
so we go through here and we can just move this 20 20 in each
now we notice from this even the one where we only went up to one
change but we see the lines on the outside do and the tick marks
in each direction there we go code test passed so some more graph
i was saying we're going to modify this this is really what we
plt.axis so what were those numbers it really was an array of x
as just one group notice the parentheses and then the open
was that defines the window size so that's why it's plt.axis so i
sense to define those as variables up here so this line here the
and then it's really easy for you to then change the window size
numbers so there we go and this one is not one oh yeah this one is
notice it should still do the same thing there we go and then
20 you know and again we see 20 in each direction
so this is going to be our go-to way to set up the graph and as we
those axis lines that you might be making and we're going to
so we have those axis lines that you might be missing i know i was
want to display these well we have our basic graph and we have the
were doing this on your own that the b that we're going to see
so we have this dimensions that we're building upon and these
subplots the window size so now we have the plt.plot and that's
points now in this case we have this array here from x min to x
what this is is a an array of the x values and then the y values
so we have it starts from x min zero and then goes to x max zero
and rather than plot to those two points it plots a line from that
and with this the line is going to be blue if you don't put
python will pick the color of the line for you and then for the
then we're going to plot zero zero y min y max so what is this
the x value of zero to the y value of y min so from zero y min to
draw that line and again i'm forcing it into be this this space
space or not doesn't matter so there we go so these two plot
plot statements define whether you know define that it's going to
and i even have the comments here so then you see blue x-axis blue
y-axis so that's it we're going to show this plot and
we also see again the the value of defining everything up here
of these the size of the graph and then where these lines go to
this up top so if i change the dimensions of this then everything
the axis lines will still go to the ends so we run it and then
so you can make it whatever you want
i just happen to like blue so there we go changing these so now
to plot a point like we saw that we did that into define a line
well see as we continue to build this define these values here and
just going to end up keeping all of this as the window size and
it blue so how do i plot exactly one point so notice this array of
only one in there and y values so it's five four now here's what
it a point in fact a circular dot so if i have just b with nothing
if i actually just had r with nothing that would make it a line
too so that would be weird but ro makes it a point and we'll see
so keeping all that the same and just plotting this one point
one point there we go one point and it is five at five four over
now we could put the grid lines in but that'll be another story so
so the directions run it then change the location to negative five
one okay so then we just change this to negative five and change
there we go and when we run it
all right so plotting a point we indicate that it's a point this
plotting a line we have other ways to indicate that
so how would i plot several points
well let's take a look all right so a ray is to plot each point
and we can still define it as an array here i'm just going to
the array here an array of x values and an array of y values so if
we go down here so notice all that's still the same and here i can
because you know x values and y values and i did not use exactly x
so we're okay i mean you really could name these arrays whatever
but there we go we have what am i plotting the array of x values
and then here i have red points for each of them now right here i
so we can add so that's the assignment for this step add two
one one and two five okay so the x value would be one and the y
so i have point four two and then point one one and the next one
y value would be five and there we go all right and changing those
don't have to change this code plot that array and we see three
because each of them i made a red point so let's mix it up let's
okay so that's it hopefully you are noticing the subtle difference
each plot statements takes an array of x values an array of y
you what you're plotting so the default plot is a line if you
it would give you a line and python would pick the color rbg
also work as just letters and beyond that there's actually a few
write in the word for the color give it a try you know i'm not
but yeah give it a try and so these are the colors so then we have
ro the o indicates a dot rs you could plot a square and then r
would be a triangle so that if you have different things you're
dots or squares or triangles and then of course that combined with
plot a lot of different things on one graph so notice we've
and i'll call this one line x line y point x point y so yeah not
and there we go so we have these we'll keep all these defining the
and let's plot so if i wanted to plot so the directions are a lot
squares so if i plot here so line x comma line y and we want it to
we go and point x point y and it's a green square gs
so you see if you've been working through the course hopefully
coming at this you know relatively new hopefully it's seeming
more you do this the more you just get familiar with with graphing
be able to do this right off the top of your head so we graph
and we will see so there's the red line from that point to that
here so there we go so we see how we can graph a line and
okay so here's a scatter plot game and i call this making a
but i kind of made the game so but we could take a look so this is
want to look through this code how can i plot a random point and
try to guess the point i made the i made this uh you know a
and we'll define this once and here's what we're doing each time
if we are we're going to get an x point which is going to be a
this is going to be good for different games or different things
a whole library of randomness and random dot rand int and it gives
max from x min to x max and actually the way most ranges work in
x max is x max it will won't go to that it'll go to the number
so there we go so you see again if i change these dimensions it
that so now if x point is the random integer then i'm going to
store this as my y value and you see essentially it is an array
you know but then and i might have been able to skip this step but
you know what what this is and now we go here i'm going to apply
uh gives the grid now this is we you know we had their axis lines
that'll help because the game is going to be here's the point you
so that's what this is yes and we're going to prompt for input
red point and that's going to be an x y with a comma so we're
and that's going to be an array with two elements so then
yes array zero so the first element cast as an integer that's
and the second element is the y value cast as an integer that's
and this is part of why i like to break it up here because i have
this defines it as an array but this is the point that we wanted
point and y guess equals y point then that's going to increment
and there we go all this in the loop and then if statements in the
and you know in range zero to three we really because we're
need that zero the range will start at zero by default so there we
it's going to go through it three times because it'll be zero one
again python ranges if it's range three it won't do three it'll do
it so we go through and guess it three times and then print out
was way at the top initialize it at zero and we'll see see what
with the grid lines we can see so zero and look at these four five
point would be zero five and here we have zero negative three zero
why i made it eight in every direction because it actually the
bit better so what's the coordinate of this point so looks like
three so that would be three negative three all right and there we
it'd be a good way to test your understanding of coordinates
all right and step nine so now if i want to graph a whole linear
define these two points and i can draw a line between them but
the whole linear equation so numpy is the library we're going to
import numpy as np now that one i mean numpy is not that big of a
just seems to be a common thing so you will see np dot this or np
functions all right and then we have the linspace function so that
an array of values when we're talking about functions we can you
this gives us that array and we're going to plot the function with
so if we take a look at this all these so after we import numpy
same setup for the graph and then linspace
we give this now i purposefully made it a little bit less you
we'll get to some other things that we can do with this that'll
purposefully a little bit less than the maximum values here on the
argument so it goes from it's the x values is what we want for
negative nine to nine and in that there are 36 points so believe
actually going to be enough which is you know four points you know
that's actually going to be enough and notice then what we're
and you see that's the array of x values numpy gives us that array
given this i can just put this equation in here as that's the y
through this array of x values that y value is going to it
what it's going to plot so then when we run this we see that it
this graph there we go two x minus three and yep looks like it
and looks like about up two over one etc okay so there we go um
um and we have this run it and then change it to graph negative x
the same now in this case since this was cut off here we didn't
then change this to negative x plus three now we see the the
here because it cut cut off there so what can we do here well we
already defined x min and x max we could actually make this go
this come up in the next things we do all right so we can create
so in this case we've been talking about linear equations let's
slider so we're going to import all these things here now you know
matplot library for the graph for the plot and then we have we're
and then the widgets so we can make all the graphing happen in a
there we go function of m and b and if you're if you're working
in this course this might be familiar and then we'll see just you
different about what we're doing here with this function so if i
everything happens in the function defining the x values y the
y the maximum defining all this and in this case we're going to
we already know that this is going to be a slope intercept
title all right and then we have there we go np.lin space and we
time i also rewrote the numbers but you could always make this
else here so what are we going to do here we're going to plot x
because these m and b values are going to come from slider and
take that so here's our interactive plot i mean i could have made
but the function is interactive and then it takes f what's what
it a range and b equals and we give it a range and we run this
to plot now notice it default goes to zero so as soon as i
with the slope of two line with the slope of four and then b is
up and i can move it down and we see that i can adjust my graph so
that we can adjust a graph all right and then if i'm graphing a
graphing system of equations that then hopefully this is a good
a look at here's one way to graph a system of equations all right
these now here's where we make it a lot better so how many points
it also based on this x max minus x min so that's going to give me
the negative so that's going to give me you know this range and
enough times 10 that might be plenty for even more complicated
have that you know there's the range and then times two and then
here we are defining this linspace from x min to x max and then
so we see again we're building these i have this comment in there
pretty soon then you won't even need that and now we again we
our complete uh our base of what we're importing and then the
so then i can plot two lines you know define y1 in terms of x
and what what am i plotting x and then y1 there we go and in line
linear this this plot works you know x squared minus three and
and then y2 and we can see these so there we go all right change
so y2 we're going to make it negative x minus three so we're just
negative x minus three and we see there we go and with these you
want these lines to be but without that python gives me the colors
know it'll go through a few colors and then we'll go through a few
light blue then orange you know it'll go through a few colors and
two points so systems of equations you know so there we go that
two equations and you can graph more if you want systems of
so the simpy library and we probably don't need to import
example so the import asterisk is going to import everything from
to define these symbols so now i'm going to here i'm going to
going to use to solve so i could define these separately and
do but what do i have i have lin solve and then notice open
for lin solve and then what do i have i have this array of these
zero so that's what you know it would be this two times x plus y
and then the other one x minus two times y plus seven equals zero
up if i want to solve these two it would be those set equal to
variables x and y and what happens when i run it it gives me this
as a point that's the solution there we go so one way to solve
and if we change these to 2x plus y minus 15 equals zero so 2x
change that and then 3x so remember three times x you know we'll
have to remember to put the multiplying symbol in there minus y so
over and that's it just 3x minus y equals zero so there we go and
so there you go one way one of the ways to solve a system of
equations solving a system of equations and you may have already
code to solve and graph and output you know make the output even
if you haven't already gotten to that you will
so now we can get the solutions as coordinates so as we saw there
but given that set we can convert that into an x y coordinates so
i split out first and second as two different as a way to put
solution i don't have to change this code then solve first second
sometimes that's a little bit easier
now we know that that solution is going to be a finite set so this
i'll call this variable x solution is solution dot args zero zero
solution dot args zero one and so there we go you don't have to
ways that that's organized especially since you know you think
one x y solution but there's a lot going on here so now i have
so now i have these as x solution y solution and i'm going to
and just for kicks i'll also print it out as a coordinate pair
so see zero zero i mean it works out
because x plus y and x minus y so they would cross a zero zero
so there we go again another way to then elevate that and solve
just showing you different different ways that you can parse these
now we can even get the system from user input so i'm going to
you know this remember to use python syntax and then notice how
to zero because i'm going to prompt for the input here first and
and the second equation and i'm not even casting these as anything
linsolve works out like that there you go first second and then
let's do this as long as as long as two things set equal to zero
plus four minus y so if you think about things in terms of y
put a minus y here so three x plus four minus y okay
and i just hit enter and it jumped down so now the second equation
all right so what if i have five times x
plus five here we go and notice the space minus y
here we go hit enter it jumps down and there we go we have an x
all right and then solving graph which
which in in this whole course the solving graph we have the
you'll see as we build and you know you get more and more familiar
ways to solve and graph then you'll see that we can get more and
here we're going to import matplot library and simpy and numpy so
so this one here we're just doing this with linear equations and
notice i'm only asking for m and b separated by a comma so i'll
i'm going to split that and make that an array and from that i'm
the first one and that must be m and then the next one that must
this input i wanted it separated by a comma so then we're going to
input is a string splitting the string makes the array and then
array the first element element zero i'm going to cast it as a
the second element i'm going to cast it as a float and that's
the same thing for the second one m and b and then everything's
split it at the comma makes that array and then that array the
second element cast as a float b2 and now that i have these
i can solve it so here we're using simpy to solve it because i'm
i'm going to give it this variable first is this because i know it
mx plus b so it'd be m1 times x plus b1 and then minus y that
and then linsolve first second and then i'm going to just in case
just in case there's a weird solution i want to take that
to three decimal places so i'll take that solution cast as a float
places for many things you know i might not need it but i give
comes up it works so there we go solution i'm going to find these
um three decimal places round them and now i have these the x
so then to make sure the window includes it rather than give it to
my normal window and this is a float so if i cast as an integer
and then i can add 20 subtract 20 you know i gave it each of these
solutions i cast it as an integer and i know that my graph is
and then given these you know points how many points do i want and
and then graph x because i already used x in other places so graph
for my x values so there we go min max how many points
and here's my y1 is m1 times graph x plus b1 and everything here
graph x plus b2 so then when we set up the graph and line one
and the point so now i'm going to plot the point which is x
okay so that way whatever equations we have and then print out the
so if we take a look at this x solution y solution we run this
this first equation all right so let's see let's call it three
one oh because i didn't put the comma
so three five and negative one
so we have these and we see these points this is the solution even
as not a nice integer decimal numbers but then we see the graph
they intersect and these are kind of the things that we want to
good way to plot and graph where if you know that it's linear then
and we can do that for other types of types of functions you know
when we get to all the parent graphs and all the different types
you see that this is one way we can prompt for you know if it's
coefficients and then that works out to solve use those
simpy to solve and use them again in that plot library to graph
display the answer all right pretty good
so the next thing we have is quadratic functions when it's not a
anymore not not a nice straight line so anything that involves x
is a quadratic so x squared because it could be the area of a
the side but i know that the area would be that side times itself
there there's going to be a parabola and here's the simplest
plus bx plus c so b and c could be zero they can be any number
because if a was zero then i don't have a quadratic
so then you know there's the simplest one so now let's take a look
back to our graphing setting up our points you know range our
up the graph and i'm just going to have a basic y equals x squared
squared and if we run this that's the most basic parabola so a in
a in that case would be one and you see it does touch it zero zero
so now quadratic function abc's let's take a look at abc and let's
and we're going to use these widgets so
so this one here all right you have a and b but we forgot c and we
put the values on you know in a different way but just did it this
now notice here it's our interactive that we want ab and c so
f and we see function here of ab but i want ab and c so
that's that's going to be your that'd be your assignment add c to
so there we go out here comma c equals and then i'll do the same
nine okay so there we go so now i have this interactive i'm going
for a one for b one for c and then when we define the function abc
and the plot is going to be ax squared plus bx and then we have to
so now when we run it now it's all zeros that doesn't look like
as soon as a is something now we have a parabola whether it be one
what does a do to the parabola you see as a gets bigger the
and zero we don't have a parabola but negative values it flips it
negative like a frown and there we go so let's let's have a
i'm going to skip over b for a second what does c do notice the
and c just moves it up or down
and could be zero that's fine it just touches it zero zero so
down the y-axis and then b is the most interesting it moves it
little bit now watch what happens when we move it so that was a
but now when b if b is zero it's symmetrical on the y-axis but
positive b value stretches on this side so there we go some
the a b and c and what they each do to the graph
so this bottom part or if it's flipped over that'd be the top part
that's the vertex so that's the point where the parabola turns
you the formula here negative b over 2a so the parabola turns
negative b over 2a so then given those inputs
then we're going to create the parabola now this i even have the
because certainly i can print x with the two asterisks for the
um just another fancier way to output this and you'll see it'll
it'll look like an exponent so supposing then we just prompt for
we know we know we're doing a parabola so we just prompt for these
then what would be the vertex well the x value was negative b over
going to do negative b divided by and the 2a both all that needs
need the parentheses so negative b over 2a because if i don't
do an order of operations now if i have that value then given that
x value so we have a times and remember the general form of
i have i have vx is my x value squared plus b x so that'd be vx
vertex plus c so there we go so i use this a b and c to get the x
and then i'm going to plug that in to get the y value of the
and then x minimum so for whatever we enter we'll just make sure
so counting whatever these values are and you know there you go
take it as an integer and that's 10 minus 10 there we go and it's
so notice just that x value just that y value as a red point and
i probably could have done this based on x min x max but just
the lin space just giving us that enough before and after it and
we plot x y without the third argument by default it's going to be
the color so let's see let's take a look so it's going to show us
that little two that was the whole idea to get it to be that fancy
one a is one and b is let's say negative negative five and c is
so we see the vertex and the vertex is 2.5 negative 0.25 and we
we see the vertex plotted so pretty cool and that's it just same
those coefficients and run it through those formulas we can plot
we did the linear equation plotted for m and b we can do a
so you know we could we could do this again and see some different
at how to apply these parabola qualities to projectile motion and
through the air is a projectile and they all actually make the
pretty interesting it can't not be a parabola so as we look at
the graph of this that we're going to look at is going to be for
straight up in the air so in this case the a value is going to be
because it accounts for gravity and that would be in meters per
the a value stays the same the b value represents the initial
on how hard you throw the ball up in the air or launch something
velocity is b and then the c value is the initial height so c
the ground you know like kicking kicking a ball and if it was on
the ball is a parabola and then in that case c would be zero the
we have our classic quadratic ax squared plus bx plus c and in
seconds and then y is the height at any given time so let's take a
what we were just doing but a little bit different so a stays
prompt for that if it's a projectile that's going to stay the same
i'm going to prompt for it and cast it as a float because remember
so rather than just say oh what's b i'll prompt it as initial
now once we have those you can and i already did copy the vx and
the equations for the vertex are exactly the same so you know once
same formulas vx and vy then if i'm going to graph it i'm going to
always 10 in every direction just seems like a good starting point
to be concerned about positive values here so i made x min
negative just so that you can see the axis same with y min made a
can see the axis but any negative values won't apply here now
up here so how do i get these well the x value i'll tell you this
so the x value of the vertex is exactly right down the middle
the middle sometimes we call it the line of symmetry so it's
we know we're dealing with all positive values here so whatever
i'm going to double it so that's why i have two times vx so there
it i should be at the end but i just added 20 just to be sure we
maybe a little bit more it just gives a good perspective on the
x value double it i decided to add 20 but then we have to cast it
ones came in as float values and your dimensions here have to be
sit with the y value i'll take that vy and yep that's the vertex
point of our projectile and i'm just going to add 10 to it i
you can see see this and it's not right at the edge also casting
need to be integers so this should look familiar we don't need to
changed this to four just to give you know four times this just
graph isn't choppy two might even have been enough but there you
to the graph and there we go we define the x values same function
then that that that will work again we need these to be integers
value as our quadratic ax squared plus bx plus c so now we're
been doing plot and then we're also going to plot you know a red
so all this is going to be very similar but you'll see the
then the graph the scale will be a little bit different so when we
uh let's call it 40 and initial height two so this could be
up in the air you know you could probably throw it at 40 meters
by the time you release it yeah it's about two meters off the
see these and you could always round these i didn't for this but
but we get the value of the vertex now what this means in time is
you throw the ball up in the air it will hit its maximum height of
83.6 meters so there we go if you could throw a ball you know that
reason i have the negatives you see the blue for the for the axis
a ball at 40 meters per second then uh straight up and you know
you know 83 meters in the air and then time wise you know four set
where it's going to hit its highest point and then a little more
ground so there we go we can see what our parabola would be and
different things relating to parabolas whether it be a ball thrown
yeah there we go so see i i just broke this out as you know see if
see just shifts the graph and here we're going to import all these
than put a slider just decided to make this and i made it a
take a look uh our x values and then we plot we decided to make
and if we take a look so what do we want in in this range
i'm going to actually didn't use c itself as a as a variable
this range then i made it negative x squared plus c and then what
plot it you know to find the x values ones up here and here's the
and this just i did that just for the sake of setting the title
so you'll see how you'll see how that comes up in the title and
and this little this little display here you'll see how that that
the notice i don't have the defining x min max y min y max this uh
just make the graph fit and each time so here's a python sleep
just in seconds sometimes sleep methods are in milliseconds this
so i wanted to display that and then wait a half a second then
and then wait so you'll see it'll display this and then clear the
so all those different c values we can see it grow and we can run
so all those different c values and notice the the y-axis changed
the larger graph so we can see that value all i have to do is you
and it's the same shape it just moves up there we go
okay so we found the vertex but the quadratic formula since we're
equations what does this do this gives you the roots now if it was
now if it was a projectile that would be when it hits the ground
think about it you know ground level is the x-axis and then you
then you know like roots of anything growing you know wants to go
roots they are the x-intercepts because it's where the line
the zeros because y equals zero so you'll see it come up with all
if i know a b and c here's the formula if i were to write it not
what x value makes y zero that's the question so that x value
the square root of b squared minus four ac and all of that over
minus because somewhere along the way deriving this you do a
you have two possible answers so that and that's what it gives you
but also notice this is the common way you write it but this it's
so we often write it like this you know all over one denominator
vertex you recognize that formula plus this and then the vertex
another just another way to write it whether you split it into two
together over one denominator but when you write it this way then
plus or minus something and again we were saying that x value of
so it would make sense that that value right in the middle and
value minus something you know that's where we get our two roots
you know they're symmetrical all right so given a b and c we have
i have again here i'm just going to import math because i need
and i have it printed out like this where i just have the comment
prints two as an exponent i think that's just a little bit nicer
found how to print that out nicer so you're going to print this
all right ax squared plus bx plus c equals zero and given that
b and c so there we go now here this is where you're going to
we'll define these variables here they're zero but we're going to
a little bit later because i want to define these variables that
statement but i want to run it through this if statement here now
minus four times a times c because remember that's what's
and if that was negative then your answer is imaginary because you
number now certainly you know some mathematicians you know years
that stop us if they're not real but for our purposes here we
the square root we're not going to go into imaginary numbers so
is less than zero then we're going to print no real roots and this
this stuff that's underneath the radical here and that's the
minus four ac if that was less than zero then there's no real
zero then this plus or minus doesn't mean anything because plus
so if that equals zero then there would be one root and then any
two roots and i think that still comes out the most common it's
these other options come out often enough no real roots what that
is a parabola that does not touch or cross the x-axis so you could
just parabola and it opens up and crosses early you know at some
you so that's the discriminant and knowing that tells us you know
than zero then there's no real roots it if it if we only have one
only one root we're just going to print that out twice and not
to translate this this quadratic formula into this well we're
going to do the very similar thing just one's going to be plus in
minus so let's try this so we have negative b let's do the plus
c all right now all of that remember was in the numerator so i'm
all this as the numerator and then divided by our vertex
okay so order of operations all this stuff python will know but
denominator i'll put everything in the numerator in parentheses
denominator in parentheses and then the second root i can really
and paste it here but the difference is it's going to be minus
there we go so now a lot of things you can do that you know in
we already did the vertex and that and finding the roots these are
you need to do with a quadratic formula so having this there we go
so let's just try numbers that work out pretty nicely one and we
try that look at that the roots are negative two and three good
nice integers but this will still work if you have you know like
you see it does have roots definite real roots but since it
and there's actually like a more complicated square root answer
this that could be a bonus bonus thing to do to output that square
so there we go the roots are this and this and you could always
expecting you know that you might have some weird irrational roots
three or four decimal places and i'll leave it up to you if you
all together and have something where whatever the application you
get the roots in the vertex and graph it you know as well as
so you know just to show you you know we can put these two things
interesting things you can try so sometimes the graph i like the
i'm much more interested in just a table of values so in this case
i made this linear so here we go we have this now notice i didn't
a fig dot or a comma x i just have x equals so i'm not going to
here the graph i just want this because this plt dot subplot in
going to give us a table and access off right because i just want
we're going to we're going to give it a title we're going to run
and notice how this works i can define my columns and i could use
it cols for columns so i can define my column headings and then
tuple of values so in this case in the first row x is zero and y
and then what i can do is in this case since i have this for a in
it from one to ten here's what we do rows dot append and then i'm
values you see so x is my a value whatever that's going to end up
then two then three and then two a you know just something simple
is how you can get a table of values rather than graph it you can
row so you set the columns set the first row and then append each
x dot set title i've already defined it up there and then take a
and it takes the argument cell text equals rows column label
know i feel like that's uh that location's you know okay this goes
just close the parentheses there just to show you so it's still
what we're showing is a table instead of a graph and you see how
both so you know that would be that would always be something you
table on the graph but who knows maybe you want one or the other
data science this is like an introduction there's some things you
or things like that but as you get into you know in the next math
when we get into the stats course we're going to look at like all
so this is just one way and you can we'll see even more ways but
there we go and you could always make this quadratic or whatever
again just for simplicity to illustrate the table itself i wanted
equals 3x plus 2 and where do i need to put this well this is just
correct thing so that's going to be the title and here i this is
a is my x value so it would be three times a plus two there we go
it you know and zero zero five ah now zero zero actually should
now one of the things you can do is you could keep this and then
and remember for the range at zero you don't need to put anything
or you could just say oh i know what this initial value is going
so you know a couple different options there
so there we go we have our table okay so different ways to display
have a nice an interesting uh mini project here so we have the
projectiles so we could have you know we could we could you could
um so what this would be is remember knowing where you're you're
randomize the height and location of a wall and you have a toy
so you can you know the game would be determined what initial
would get the rocket over the wall and you could take it even
path or you could you know there's some other things you could do
to write but i'm going to show you here's one thing you know one
so we imported all this stuff and actually a lot of the things i
uh one of the earlier steps where you're graphing a projectile so
and i'm also going to import random and import math so here i just
so this is the what it will print out it just has to land so many
randomize also like h for the height of the wall i just made it
so here's this random integer between one and a hundred and then
rocket has to land this many meters away and then we'll go through
so input initial velocity and instead of it it's zero zero it
you know just because but it really could be zero and then same
the vertex here and the x min what i would do is x max now i just
i know that the wall is going to be you know anywhere between
i just left it as that so and the y maximum i left it so that you
projectile goes but we could always go back to what we were doing
and y maximum the same thing where we get this that where we get x
we could always copy these because that's what we want to do here
and that was that was the idea i want you to you know make use of
these these later steps that's really what what it is i want you
have and then maybe modify it a little bit there we go we could
because wherever that wall ends up being or the the finish line
print everything and that'll be fine there you go path to the
the lot the line for the distance and i'll just make it a red line
i just have it go all the way up to the top here location my two x
y maximum so that's just going to be a line if you wanted to also
you know h equals and we'll do the same random integer
where do i want this to be i want this to be i don't want um
a hundred's probably plenty you could even make it a thousand
um you'd be surprised you know these rockets um
so many meters away and there we go so if h would be the height
the height of the wall would just be h so that's the slight thing
times the wall the scale of us the wall end up being so tiny but
that there so there we go so the line and plot the parabola now
pick just one of them and as it turns out because of the way you
b minus is the root that we want that's the one that's going to
that's the one that's going to be greater than the parabola so
quadratic formula again and the way it displayed i wanted to round
places so here we have if root two is greater than or equal to
distance i wanted to print out the distance and then tell you
much here we go all right so this is it there is actually no test
here we go a rocket has to clear a wall 85 meters away initial
my initial velocity 300 and then we see that initial velocity is
then we're still we didn't clear it so missed it by that much and
things you can do with this so 19 meters away i'm still going to
velocity of 250 let's make sure we clear it you see and we see the
did clear it now some of the other things you can do is you could
that distance take that as your x value of your vertex and you
always make a parabola that perfectly that perfectly clears this
interesting or you could modify this game to say that it has to
um not necessarily that distance or more but maybe you say all
exactly 50 meters away and you don't want to miss so that would be
you could you could actually write the code and i'll leave that to
as for something you could write the code to calculate the
so there we go now for this you know upward motion one of the ways
you know whatever the distance half of that and then that's your x
of the of the vertex and you can use that to calculate you can you
some formulas and as i said we'll get even better formulas as we
we will do things to adjust the angle and such to get it to be
so showing you how to make a projectile game i think it's pretty
you know that you could and you could even make it you know like
have to how many ones do you get correct but there you go the
the this is going to be more like the open-ended part all the
you you should put this together in a function that will graph or
a table solve a system of equations now if you've been working
you might have some of this already put together and that's where
here is you know hopefully you've built up to this so you know you
i know how to do this and i have some of this stuff in place so
organize it use some of the code that you've already made you know
different functions because then you get to the certification
display you know this is what you want to do build the calculator
and a table for any y equals input cool and you can make that
very clear in the code that you know here's where the equation is
graphing graph two equations and plot the point of intersection so
pretty big you know graphing the two solving and graphing and
in the vertex so that'd be some things you know we've been doing
do some things with quadratics enter a b and c see the graph plot
maybe also print them out you know solving and graphing systems of
showing the table and then you have you know these projectile
game you have the scatter plot game you can even modify that
you know something else that might be interesting so there you go
working on you put it all together to build this graphing
certification project and by now you're even deeper you know what
we're about to then have some more twists and see some more
so what do we mean by parent graphs and we'd have heard this in
child graphs have everything that the parent graphs have plus some
additions and so these paragraphs are the basic patterns that
so let's take a look at this the one the most basic would be y
just call c here and so that would be this blue line here just a
y equals three or y equals four or something like that it could
nothing else and whatever the constant is it's always going to be
call it a parent graph and whatever the constant is that graph's
you know flat no slope you know nothing else going on just y
and that's why it's a parent graph because that's like the basic
things like y equals mx plus b well the paragraph for that is y
b is zero and just that basic it's not y equals a constant because
right the paragraph is just y equals x and then we can get like y
or anything like that we can have other things so this wouldn't
things you know i have a slope or i could have a different
this so that's the parent graph another one i wanted to show here
of this works better than somehow sometimes how it plays out with
function and so it's this step function some people call it step
greatest integer but the floor is when you're not rounding you're
it's 0.9 doesn't matter we're just dropping all the decimals so
these decimals it's zero until i get to one now it's one and then
until i get to two so that's it there there are no in between
and then at the next integer it jumps up so again that's a parent
the ceiling function where no matter what it is i go up to the
they're all very similar looking graphs just shifted a little bit
a parent graph we talked about x squared as a parabola and i
even the axes for these because i want to get the idea of this
it's kind of like half this parabola bends down now the reason why
as you get into like x to the fourth x to the fifth all the even
graph look more like this all the odd ones look more like this but
going on in that graph so remember x squared could have ax squared
had other things going on it's still a parabola but it's a little
maybe it's like a little bit narrower a little bit wider or it
still be a parabola the x to the third if i end up with x to the
then that those curves get a little bit deeper
or you know that's you know again paragraph and then beyond that
and we'll take a look at some of this in the code too and the same
so x to the fourth is going to look more like this maybe a little
but if i had x to the fourth plus a bunch of other things in there
something else times x you know all these other things that could
most you know x to the fourth could turn around one two three
always perfectly symmetrical but if all the if all the exponents
symmetrical kind of cool it works out that way so these other
we could have other things going on and i didn't want to draw a
talk mostly about it when we get to the code because that way we
way python displays the graph is going to be much better than my
parent graphs these are the basic patterns the simplest pattern of
and then we can look at what what else we can change or add to to
that affects the graph so let's take a look at the code so here
parent graphs and the code to create them and they're all going to
setup we've had so far for setting up any plot mat plot library
our points set up the graph so this simplest one is a just a
equaled any constant number notice x is not even in there just y
this in the same way that i'm plotting the x-axis i'm just going
minimum to the maximum and then y is just always going to be five
a red line and that's what it looks like it's a flat line there's
that whole part of the equation no x value and y is just always
y equals you know seven point five or y equals two or you know
no slope so that's a constant graph
and then the linear graphs we were talking about linear graphs but
the simplest linear graph y equals x so anything else i do with
in this case it's y equals one x so the slope is one plus zero so
so again the simplest and then anything else i do that is an
so there's our simplest and notice everything else i do to set
my x value and then the y value is x so there we go x x and
the slope is one and it just goes on the diagonal like this there
so every point here you know three three four four five five etc
so the quadratics we were looking at quadratics this is this basic
y equals x squared so before i do anything else to it that's just
and here we're plotting this my x values and then the y value is x
so our parabola so in this case you know x squared so a is one b
and then any other thing we do to the x squared you know add other
uh three x plus four or something like that or some you know
is uh an offshoot of this paragraph so there we go and i can make
and we see the negative a flips it upside down so we have you know
like a smile so i'll go back to the smile there we go again the
x squared and then a cubic graph y equals x to the third so the
it's like the area of a square if i know the sides the cubic x to
volume of a cube if i know the sides so setting up the graph here
about later just starting out with the basic x to the third and we
so some you know some of these you know i could sketch it out
kind of looks like a parabola with the left side flipped down but
simplest cubic graph so what i wanted to show you is also
have other things so plot the x values and supposing i had like x
squared minus three x plus four you see i can have all these other
and this is how it affects the cubic graph you see it gets these
kind of flattened out before but x to the third is going to turn
we go we see these possibilities here all right so again you know
this is you know a more complex graph the parent graph still is x
so we go x to the fourth and yes they have a name too quartic so x
even exponents so we see i'm just plotting x to the fourth all the
this so x to the fourth if i also had like x to the sixth notice
need more points to make this look smoother but you get the idea
beyond what i can graphs what i can draw so i like showing showing
even exponent graphs uh we might be able to do x to the eighth and
that looks kind of horrible so x to the fourth is probably the
other than that then we have to change you know how many points
it a lot smoother but that's where it kind of looks like a problem
around zero and all of the even exponent parent graphs will look
x to the fourth plus other things and then the graph would look
go up and down as many as three times i could have as many as
you thought we were going to run out of names but nope x to the
quintic all right so x to the fifth and when we look at this there
looks a lot like x to the third so all the odd exponent graphs are
but again just a little bit more flattened out and if it's just
other things then the graph could be all all over and it could
but there we go so all the even graphs are like x to the second or
the y-axis and kind of looks like a flattened parabola all the odd
the third the fifth all the odd numbers look like this you know
then with you know as they get more complex with other things
beyond the parent graphs then we have all they can actually have
value graphs and there's a lot of patterns with absolute value
as they would be for x squared graphs the way the vertex can move
value graph is just this absolute value of x but like the other
something here inside the absolute value or outside i can add or
so this is how i would write absolute value with the two vertical
parentheses and here's how i would put this in code abs and notice
anything that's part of the core python library so that's the
then it looks like this because absolute value means it's just the
negative doesn't matter it's just the number so it would be like
would be in the positive direction but y equals negative x so for
y value is positive because it's absolute value so that's why
the y equals x graph it comes to a point and makes a v so there we
whatever x is it's going to end up being positive when you square
all it just doesn't do anything except make it positive and so
similar patterns to some of these but there you go perfectly
that's the absolute value graph and then i can have square root
how i write the square root if i was writing it out and if i'm
now there's math dot square root and there you know and other ways
going to use numpy dot square root because we're already using the
else so since i'm already using numpy for everything else that i'm
want to use np dot square root so the the comment we'll talk about
square root graph and we can start talking a little bit about
is the inverse of x squared and that's why i also included this
it you see now just the square root it's just going to be positive
negative part then that's not a function these x values have two
them together i see that it looks like a parabola on its side and
the inverse of x squared because i want to do the opposite i
helps us see it but the full graph the true square root graph is
function all these x values have one y value and then there is
beyond this all right so there we go so there's the square root
is with a rational exponent now overall for this graphing python
so i'm going to do this here and i'm going to show you that this
x to the one half exponent but if you try this for any pretty much
half it's just not going to work it's just going to give you an
there you go that's the same that same graph so x to the one half
graphing it you know it works out nicely the denominator is your
so square root denominators two or if i had a cube root the
to write it like this here x to the one third so that's the cube
times itself three times gets me x so like the cube root of eight
two times two is eight so we're getting the cube root and i don't
exponent here because numpy just like there's a square root
so that gets the cube root and this one i can have negative values
up three times i can have negative negative negative so that works
the cube root of x there we go so somewhere around here i have
you know there we go and then we get the cube root so the all
the other ones i could have other things going on in this equation
that would shift it up you know i can move it around but you know
paragraphs these types of shapes and then other graphs are just
all right so the floor function now there's the floor notice it
value but the it does have feet at the bottom that go underneath
to show you the floor the uh other function that's similar that's
and the floor function is the one where you drop all the decimals
like 5.9 and it doesn't round you just drop it and the answer is
just drops the decimals and just takes the whole number other
integer function or the integer part function same idea there's
matter what the decimal goes up to the next one and we have round
and to plot the floor function now i want to show you this this is
the function np.floor but there's a reason why i didn't do that
in a loop to graph this as a bunch of points because i feel like
function a lot better it does give these steps and sometimes on
a step function so it's the same value until you get to the next
and it's that same value until you get to the next integer
so all these are just sudden jumps once it gets to the next
change because if it was 3.1 the floor is 3 if it was 3.5 the
values if the floor is 3 and then when it gets to 4 boom then it
went through all of that is that the actual floor function i feel
show you you see it gives these values but these vertical lines
because it's not continuous like that and so it's just what you
but that's what the floor function looks like in numpy but truly
it looks like so that's why i wanted to do the loop and show you
floor function exponential functions so now we go from things like
is the exponent so what happens when the base doesn't change but
so that's two to the first to the second to the third well we can
value is going to get really big really quickly
and so here to the exponent of x so we have we see it gets really
and then when we think about our exponent rules when x is zero
so all these exponential functions cross the y-axis at zero one
flips it to the denominator so two to the negative first is one
negative is one fourth and so the negative exponents for negative
get smaller and smaller so it has that curve but it's not at all
that just gets smaller and smaller but actually it will never
where you can keep zooming in you'll see that it just gets smaller
zero and then over on the right it just has that upward curve and
is never perfectly vertical it's just really steep and so that's
functions we use this a lot of times in percent increase compound
but there we go that's a lot of the exponential functions here
all right so there we go so these are all the key parent graphs
all the other graphs you're going to look at in algebra are going
graphs oh it's like this graph but then with some some other
uh later on when we get into or another course in trigonometry the
and one of the big differences is they keep repeating these are
thing and then that's it but we'll get to those graphs but for
the parent graphs so when you look at a graph and you want to
be that generated that graph you you say well which parent graph
like this so it could be you know an exponential oh it has that
different one so you know that's why you want to get a sense of
develop equations to fit different curves later on and we'll get
so there we go and you will have this as a resource too to consult
different parent graphs now that we've worked through the core
through some extra problems and i'm going to work through extra
so you can see how you can apply these resources that you're
use these to solve problems that might come up in a textbook or in
go through some more extra problems here so now that we see these
little twist here let's look at the these sliders we can add to
that's it that they're meant to be modified so that first one y
value just it's that horizontal line if we add a slider now notice
that you know we're going to import this in line and it's a widget
our graphing is going to be in this function that we redefine here
f because i wanted a shorter function name f of and then it's
in this case we're going to also also going to zoom so all these
slider so you can zoom in and out and we still have these points
here within the function set the plot and notice all this same
all this and so mathematically you know if i if i wasn't writing
y equals a but we're going to put it here i'm going to have two y
perfectly horizontal line we kind of have to do it this way and
horizontal line just like we did with each axis you know the x
y values y one and y two which are both the same which is whatever
slider you know run this function f a goes from negative nine to
we run this so there we go and as i increase the slider so we see
in a little bit but that's what we get like y equals some constant
that parent graph it's still the same look that horizontal line
graph to the child graph it just it just changes where it is see
then the zoom that becomes even more interesting when i have our
now i have y equals mx plus b what happens when i use sliders and
m b and i'm you know i like the zoom in there so i'll just keep
so we have everything for the zoom now here and these next few we
numpy linspace and that's the array that i want to graph for my x
i have y equals mx plus b so look at that m and b are still
is going to affect it and then that function is going to take that
slider change the m value change the b and i still have the zoom
so it's right here because the slope is zero but what happens as
now i start to see my graph and i can see the slope and then as b
we can see it the y intercept moves up and down there we go and
you know now we have some more that we can see when we zoom in
one i didn't put the grid on there but just to show you that as
you know that's really just that's the paragraph y equals x
i can change the slider and see the negative values and from that
two values makes it its own graph but it still is that linear
graph still has those core features but then we modify it a little
i can change the slope i can change where it crosses the x-axis
illustrate this so we have now three variables for our quadratic
and so my function i'll take a b and c and zoom in
so then my y value is just this standard quadratic i remember x
a is one and then just x squared that would be the parent graph
parabola but then when i have these three it still has that core
parabola but then i change and we can see what a b and c do to
i'm going to adjust a b and c and as well as the zoom and so we
middle so let's just put a now that's one but we can use these
to the graph when a increases you see it gets narrower and then
parabola anymore but then as it's negative it flips it down there
affect you know we'll bring it back up to positive like a smile
jump to c next because that's the easiest it just same shape it
negative same shape and it moves it down and see each time i move
again and then recalibrates it with these new values and then b i
interesting because i move it as b increases it dips down to the
and then i can bring it back and then as b decreases it dips down
it dips down to the right so just some interesting things that you
this would be x squared minus 5x minus 5 that'd be the equation
minus 6 and we can zoom in and see you know i i didn't put the
you could always do that too so we see these sliders now the
want you to notice with absolute value how similar those patterns
value because remember whatever x is if you square it it's
makes it positive but the core absolute value function so you see
in three different values here from my absolute value parent graph
because i have a times the absolute value and then inside the
that's where the b shows up and that shifts it left or right and
so we see that plus c shifting it up or down and let's take a look
got nothing as soon as i change it now i have my absolute value
this is linear each line is linear but then it comes to a point
were negative the absolute value makes it positive so we see some
as a increases a times the absolute value this gets narrower just
and c keeps the same shape but just moves it directly up or moves
we have b this is this just moves it exactly side to side so
the parabola there's no other deeper curve to it it just moves it
you know c was more it's still it still moves it side to side
it still moves it side to side so b is negative eight so the if we
then we see that that is the x value
value so it's at negative eight and then because it's b it's x
is the is the formula so b is negative eight then that means
makes it a positive that's x plus b in the inside the absolute
and then c is three then we go up three so we can see again you
and we see the basic absolute value and then what each of these
similar to the quadratic but that has its own its own things and
the most useful i feel like for a lot of algebra you know more
functions can have a slider too
and this one it gives a runtime warning which i just left in there
the you can't take the square root of a negative number so you
zoom values that i could you know at some point i get a negative
compute it won't show up but it actually that doesn't break this
but then that's it so here if i take a look at b and i make b zero
so again everything zeroes out where is it but if a is anything
and we can zoom in a little bit see this curve a little bit better
and then we see b it moves it but remember it's because like the
so when b increases it's really x minus three moves it three to
and then c also you know moves it up and again we're looking at
where that square root function starts whereas if b was zero and c
we start at the origin zero zero so we see you know your basic
these different values you can have a times the square root and
b and then i still have plus c outside that can shift it up or
parent graphs all these key things and we start hopefully you're
how this comes up and you can have these sliders with all
now all four sliders and we can see you know x to the third now
as this to show this is what happens you know a increases this you
bit narrower but b is even zero c is negative d is even zero
set up you know that's where you get you know some deeper dips in
so and it's usually some mix of positive and negative coefficients
dips and you can do the same thing x to the fourth and you can
x to the fourth would also have a times x to the fourth and then b
c times x squared d times x to the first and then the constant e
the zero so there we go and having these you know we can adjust
always symmetrical but i picked one that actually could make it
notice where the zeros are because x to the fourth a is the
b is the coefficient i made that zero x squared c is the
first i mean that zero it's symmetrical because all of the even
the odd exponents zero out so these even functions happen only if
and notice i can have an e value because e is x to the zero and
so there we go so some things you can see when we have sliders you
floor function this is just kind of cool and so what i did here is
but i made this floor function i did this
to make these a bunch of dots because i like how that displays the
that's really like this is really the floor function and i made
the points instead of lines and you know they're big enough that
between but that's really this is really the floor function as we
know if a increases it just gets steeper and a could be negative
but it still has that step look to it so and then c it's almost i
but that's it so this is the floor function we have the different
have that's the parent function just the floor function but then
parent function would be yes i would have a times this so i keep
nothing else going on that would be the parent function and then
these you know that taking it beyond the parent functions you can
kinds of other things for you know there we go some some other
oh this was the uh exponential function we'll end it on this here
my a coefficient and then b to the exponent of something cx minus
nothing going on because a is zero but if a is at least one but
i have uh b has to be a value it has to be one won't do it it has
it has to be greater than one and then c it's c times x this won't
the exponent zero out so again it would be a constant that has to
and there we go we can zoom in a little bit
a little bit there we go and you know d that could shift it and e
doing before but you see these there's a few of these that needed
show something so we see you know again general parent graph of
the things we can do to shift it so applying some of the formulas
in algebra we can use these for business applications like demand
would be how many would i be able to sell so imagine if we're
and i find out that you know an average price of like six hundred
will get me you know i might sell like 84 million computers so we
you know this might be the case and then maybe i find some some
oh well you know what our average price is going to be triple it's
the neighborhood of 1800 hundred dollars but then maybe they'll
and then we look at this and we say okay well what should my price
we can find this we can use these two as you know an x value for
how many sold and we can do the slope formula and we can get an
being linear and i can take a look at what the demand might be so
84 minus 8 over 600 minus 1800 so remember our slope formula from
if we have 76 over and then the the denominator happens to be
get that into an exact decimal that would be my slope and you know
something like negative 0.06 so then i could get that into a y
um you know somewhere around there negative you know 0.06 x plus
what would be my y intercept i could i could go through that same
the code i'll show you that we can just bring in these formulas
a couple points getting our slope intercept form and then i would
there we go and yeah it's probably you know i'm gonna just rough
so let's let's just say that that would be it and then that would
as the price gets higher you know we would graph this as you know
and we would see that as the price gets higher then the number
you know less and less and at some point actually the why are some
and at some point you know we the price would be so high that
that as the general estimate now let's just say that's the
be the demand equation and a lot of times economists are looking
um business owners too what would be my ideal price point well
i do to figure out my revenue well my revenue how many sold would
as i was saying is defined as the x value so at every point i
the demand and in this case that price is always going to be x and
times negative 0.06 x plus 50 and you see that would be my y value
quick distributive property we recognize that this is
a quadratic with a negative a value so that means it's going to
and so when we look at this then
if i have you know the price but then instead of the number sold
i want to have revenue so of course if the price is zero i have no
there's some other price that is so high that nobody buys it so i
of this graph is going to be a parabola that opens down so then i
parabola that opens down so then i see that there is some middle
and that's kind of the thing that we want to look for you know
the slope formulas we're using the formulas we've developed to
this would always be true revenue is price times demand so then we
quadratic and we can graph these we can find out what these what
so pretty interesting then we could also apply this to profit so
we could do this and then subtract subtract the total cost we
some of the applications that we want to get to that you know
based on some data you know what should my price point be to
if i already established a price point what would you know can i
are things people put in their business plans so we see these
and i when we look at the code i have two other examples so we can
together that you you know you can use your math skills you can
to make some business predictions and these are some of the good
of of all this math and writing code so let's take a look at the
to give you an another example or two to show how you can write
and for this example i'm just saying we're selling t-shirts and
they seem kind of realistic but you could define the price here
here so if we define the price and in this case we're going to say
dollars each and then we have the demand as our next variable and
giving away t-shirts maybe you could give away 50 you know this is
not really going to give them away but then your demand decreases
time the price increases increases now in this case again if the
away 50 right here the price is five and then so two times the
be 40 but you see how it just cascades we just define the price
about demand and then revenue is going to be price times demand
standard formula the price you're selling it four times how many
we've you know once we've defined these then we have these other
on them and then the total cost so this is another one that you
uh made it so i said four times the demand so if we have four you
it cost four dollars to make each t-shirt all right and i'm sure
but i just said four dollars so that's where the total cost would
you know however many we sold and then that's the total cost so
minus total cost makes sense what's the rev how much money do we
and how you see how we have all these we can just define these
formula for for profit revenue minus cost and this is a standard
demand and some of these then we could develop these equations if
data so if you're making things to sell you would definitely have
how much does it cost to make but there you go all these then if
demand equation we can calculate all these and we would output you
and revenue because five times forty and then the total cost we
dollars and then having these this is where people can do some
oh well let's say supposing i decided to make the price ten
and we take a look at this the price increases the demand
but the revenue increases and so given that cost we still have a
of more than double so the price of each doubled i went from five
profit more than doubled it more than quadrupled so just
here and how does this happen well it might be it might be helpful
we're going to graph these things import matplot library and i'm
going to remind you here that the price is x and the demand is y
that the demand later is going to be the revenue now this is where
you would have you know if i have at what at a certain price what
and i had in mind here you know that this was you know i don't
you're buying two dollars 46 so it would it might not be t-shirts
but let's just say you know i don't know bottle of water and you
maybe you hype it up and tell people it's just this amazing bottle
or if it's really hot that day and water's cold you know you still
something else that you you might have but there we go so we can
one so if it was two dollars then the demand is 46 if it's ten
to 30 as an example if just having some of this data from some
these formulas we did back with linear equations because this is
demand or x and y so i'm going to calculate the slope based on
intercept and then this becomes a y equals mx plus b equation so
you know some examples of some data that we have that we can we
that's going to be my demand equation and i'm going to go through
now notice this x minimum and y minimum i'm going to make zero
aren't going to really have any practical meaning i'll make the x
there we go the number of points that's all fine so after i define
i'm going to do a couple other things i'm going to do the x label
and then i'm going to give my graph a title so notice both these
there we go and then for this one line one i'm going to have so
equation y equals m the demand equals m x plus b and so we figured
and so i can use those but i'm going to use x because that's the
defined so we have our demand equation and then i'm going to plot
label is still going to be price but for this one y label is going
to plot x and then the demand i commented this out we'll get to
so here we go so i have my graph and then we see yes if i was
give away 50 the demand decreases as the price increases so at
um you know whatever i'm selling here that started out as two
something you know some people still want those if i have 25
nobody wants it and then somewhere in there we have the ideal now
linear in real life but this is a good estimate so given these
equation and as we were saying before i can build upon that and i
revenue equals x time demand because as long as i keep that
and then so now i'm going to plot my x value and then revenue as y
my y label to revenue so we see that we have a way to do this and
of course i'm going to make no revenue if the price is zero and
going to sell none so i'll make no revenue but this is how the
interesting that i can have some you know low prices and i think
best i might sell the most but the revenue actually there's some
that gives me my maximum revenue and you see it looks like now if
and at 25 these parabolas are symmetrical so it's exactly 1250
or if people like round numbers you know 12 or 13 so there we go
use all of this and we can see that the you know the reason why
where the demand would be zero so this is probably the more the
one but having given getting some research of given prices demand
a couple values here then i could plot this out and i can plan oh
research that i've heard what should i make my price you know and
that people can do you know you have some new product how can you
all right and there you also then if you're making a business plan
download or export these images you know you've you've written the
the graph as an image to include in your business plan so there we
examples of how we can make use of these you know formulas the
generate some graph or some image and some data that we can really
okay so let's apply some of these graphs to some other economic
python your math to plan predict you know look at trends in
profit and if we take on that marginal cost revenue or profit if
when making and selling one more product and for some of our
equations and for that the marginal cost revenue is the result of
and for that the marginal if cost is linear the marginal cost is
wherever you are but sometimes we have costs or we saw that
revenue that are not linear and therefore we have some times when
from a cost revenue profit perspective to make one more and
sometimes you know oh that one more is only going to get me a tiny
and cost sometimes it goes the other way you know setting up
be a really high cost but now it's all set up so making two three
you know might make that worth it you know things like newspapers
you know there's a big setup for the printer and so the marginal
it now there's definitely you know other methods printers but for
big printers like a newspaper marginal cost it'd be a whole lot
going to print thousands and thousands so the marginal cost after
a hundred thousand newspapers printing one more is almost nothing
things you know what what's it cost to make one more and you know
and profit the same thing and so if we have revenue you know and
comes up but you know toward the end of the day people say oh what
make one more sale you know maybe it's a store should i stay open
tired to make one more sale that might be you know a lot more cost
little bit of revenue not worth it and so they say okay these are
so these are some deeper analyses as we get into things beyond
we can do even more than that makes that even more interesting but
know as we talk about this the marginal is that at any given point
to make one more all right and let's look at some other things
and here again i'm going to give some simple numbers and make it
supply and demand graph it's not going to you know and in real
linear there might even be a little curve to it but even at that
it might be you know a little bit of a bumpy line but we have
definitions are at supply how much are people making you know
i'm looking for and the demand how much will do people want how
so you know if you're looking at you know a movie the movie
theater the supplies there's only so many seats you know only so
a play or a concert always so many seats only so many showings so
and then the demand could increase if it's something really good
so a lot of times we see that you know that affects the price and
look at supply demand and price and we're going to graph supply
we'll see some similarities some familiar things here for the
values as old demand and new demand and i just gave them this
x values as old demand and new demand and i just gave them this
it reminds you that it's an x value so we have old demand and new
the demand increase and then i have old price and new price so now
we'll see this on the graph but the price is also going to be the
i'm going to have supply old supply and new supply i made that you
as i was mentioning you could potentially get data from a table
data you could have one table that has you know a particular price
and you know make all these numpy notice i did not import numpy
putting a few variables here and you know to illustrate the graph
get that data from a table and you know make each of these numpy
that would be really interesting too and that's something that
course so given these and then i have a basic graph set up adding
going to make the x label quantity just general quantity and the y
and i have this title which i already graphed but we'll get to
and i'm going to plot this as a red line just because all right so
i'm just making this just like i do it with the axis i'm going to
and these two y values and make you know make that a red line so
not going to even put an equation to it i'm just graphing this
to this point and i'm going to do the same thing for supply as a
just going to use this data that i had these numbers that i came
um and this graph we can take a look at this again it's simplified
of supply and demand so if i made green supply red demand then we
quantity so the green that would be quantity supplied and the red
supplied and the red that would be quantity demanded and then on
so graphing them both on price we take a look at this and we see
then the quantity demanded is going to be low and a lot of times
um an independent variable on the x axis and we think cause and
correlations so i'm not saying necessarily one causes the other
so uh at the when uh x is let's say one and y is 14 so we look at
low quantity of demand when the price is high and then as the
increase as the price decreases so that's what happens oh you know
you know $14 no i don't i don't think i want it but as the price
you know the demand increases more people would want this now
this they have a different incentive they want to make money so
the and when the price and when the price is low then nobody
into this so you see we have low demand but we also have low when
is low here then nobody wants to get into this what you know why
if i'm you know whatever i'm selling is not going to be you know
the green line the quantity supplied will increase as the price
industries that you know oh you know why why are people you know
because they all see they can make money oh this is the hot item
you know uh make money so that's what we have that the supply
increases so there we go so we have these two opposite trends and
core of economics because as you know i get different data this is
as an example but these graphs could shift you know maybe there's
this that maybe you know instead of uh the supply increasing like
causes it to increase a little bit steeper or maybe you know if we
supplied is low here for this price but maybe you know for
level was even at a higher price and this whole thing shifts so
of economists are trying to do and then if this is quantity across
where these lines intersect and then that would be the point of
saying is the quantity here supplied and the quantity demanded
that's ideal you know you know let's say you have a bakery and you
morning and then at the end of the day you have it all sold
on the left you know and we'll say let's say that you know for our
at six but let's say a little bit before that so it's still to the
so the demand's not really there the price is increasing but not
not really there and we still have a gap between demand and supply
line is higher there's more of a demand but not enough of a supply
side of that we have more of a supply but not as much demand and
be on the right that would be the one that's dangerous for anybody
because you know they're getting into this trying to make money
where somebody's happy oh good the price is going up i'll make
the demand drops off so now they really have to scramble for
the price here or on the left for the people who want this product
supply and that's part of what keeps the price higher because the
supply well then the price increases you know things like you know
about this stuff all day anytime somebody wants to too many people
oh well then you know the supply increases too many and we go to
sell this you know then other people notice that you're oh you're
and then the demand kind of goes down you know what's wrong with
and on the left then we have the price is too high because there's
and you know that sometimes causes oh there's you know there's not
sell that you know this must be good and then that kind of
bit so you see this one simple graph describes all these
know our goal all around is you know finding these points of
you know therefore everybody you know making whatever products are
for these products are finding them you know and you know fair
prices we're all trying to get to that but we see all these things
and it's not just one direction of cause and effect it's multiple
as just general correlations all things happening together so we
say we say the trend is like as the price goes down how does how
it goes the other way too as the price goes up how does that
that is elasticity so elasticity is how quickly does uh demand
and we can look at this there's the formula percent change in
and this is again all these economic formulas i'm just going to
that when you have these formulas you can use this you know get
then use it to calculate these formulas to answer these questions
how elastic is that price because if things change if the price
changes demand then we can say it's a very elastic like it like an
bounces that you know it stretches and changes easily or things
it does not change demand you know things like uh gasoline you
price goes up we don't like to pay it but if the price went up a
car so that demand would not be very elastic the price could
and you know we can so we can see that if the percent change in
know some significant number but then the percent change in demand
calculate that you know the total value of that fraction is going
um and we're going to say that's not very elastic but maybe some
you know a concert ticket you know there's ones i've seen where oh
i'd like to go see this but the price is too much no i won't go
oh i heard the price went down that would absolutely change the
i i won't go oh the price went down now i want to go and that
that aren't essential and we would say that that would be very
and you know down the road you could always combine all these into
just going to show you like just old demand new demand old price
calculate the percent change so remember then that's you know the
there's their difference divided by the old price and it's going
to a percent so you see again and we want to get in the habit like
you know colab that oh i have a formula i want to use you know
and then now all we have to do is change these values up here and
that we need so price change and that's the ends up being the
with demand the new demand minus the old demand and that's the
and that gives you a percent it will give you a decimal that you
elasticity number is demand change divided by price change so what
print that number and here's some of the analysis so again
what's the cutoff point you can always just put these in you know
statement and so if the number is greater than one then i'm going
and notice this is you know else if so i just continue this on you
one then it's unitary or proportional so sometimes you know we we
increase i think that that proportional increase increases demand
and then if it's less than one then that's inelastic that those
you know again it the demand hardly changes based on price and i
and so you see this is how you can you know i i like to when i do
tag on one more thing at the end you know for whatever reason
capture everything if it's it's either greater than one equals one
really but capture one other like grab bag you know what you know
very often we'll have if and lf without you know exhausting every
easily just put an else there at the end so i have some sample
and it would print out so we get this negative 2.2 and then demand
so as that example and we can do the same thing with supply so
um as price change because people say oh hey i want to this is a
into this or then people say oh nope it's uh you know this is
so in uh it you know in the united states kind of recently the
market uh was hot and that's supply like okay not everybody
house or try to be a realtor or try to sell some property but when
more people decide to get into it like oh maybe i will sell this
that if the price is good and people see oh opportunities to make
so price elasticity of supply answers that question how how
to changes in price so very similar formula percent change in
and just a few values to sample and very similar formula you know
divided by the old price and uh new supply minus old supply
and we're going to go through the same thing elasticity number and
greater than one it's elastic which remember as a fraction greater
that this percent change in supply is much greater than the change
and we have to do percent change because if we just do you know
number of things supplied that really doesn't always give us a
in general are low cost so a change of a dollar might be a whole
high cost like you know a change for a car that a price change of
at all so same thing with supply you know what what's what's the
relevant to the previous supply so that's why we do the percent
you know a certain percent but supply change is a lot more related
oh wow that's elastic people are noticing these trends and we can
analysis either supplies elastic unitary or any elastic and i just
there we go this number and it's inelastic because it's this tiny
everything you know supply cannot always be you know elastic and
and given the old prices and old supply you could always take
something like this so that therefore you could graph and if you
other numbers so notice this i mean even though these numbers
bit of research that you just had a few values here you can get
you know six things calculate you know the graph and elasticity of
and really just get a handle on you know where where you are in
potential changes you know is it you know these graphs i kind of
proportional but you know very often it's going to be bumpier and
graph and what's what's what's going on if you really wanted to
there's other plugins for other uh data especially things like
use this uh to calculate elasticity for various stock prices you
um and a lot of these it'll work within colab there's a lot of
that are a lot of things that'll work within your google drive and
to update things like stock prices maybe like every 15 minutes at
going to be enough to give some sort of analysis you know for an
different things you know that's kind of what we want to take this
formulas and build upon these so that you know you can uh build
at some reasonably regular level have all the formulas and
you know have this output at some sort of report for you let's see
time you know pretty much real time let's run through some
thinking about investing in this what's it looking like oh it's
elastic so you know you really have to take notice of the price or
i see this trend maybe you know a supply of something that maybe i
all these things we want to you know use this information to uh
want to invest in yeah and you can do this all right here in colab
drive so uh we'll get in some more some some more math now and you
journey so let's talk about calculating interest and usually
bank or in some investment or sometimes it's going to be money
am i paying so the simple interest formula is exactly that simple
it's good for you know not a lot of money if it's long term but
the less accurate it's going to be and we'll see why that is but
rate times time it gives you the interest so if i was borrowing
you know i have borrowed you know a hundred dollars and the rate
0.05 so the rate's always a percent converted to a decimal so the
and as a decimal it'd be 0.05 and then the time would be always in
i borrowed a hundred dollars for two years then what in what extra
so there we go that would be another ten dollars
so what i would then say is okay well you know given this rate if
and it's going to take me two years to pay it off you know maybe
years to pay off a hundred dollars maybe calculating interest
if you know i could calculate oh how much extra would that cost me
the total amount that i would pay i would take that interest and i
principle because i have to pay that hundred dollars back plus the
take a look at this you know if time is one like let's say one
compounding that's the notion of compounding that i'm taking that
the principle so let's say the time was one year and so
so this would be times point zero five times one then the interest
and then what am i going to do i'm going to i'm going to add that
you know the principle plus the interest
um is is going to be five dollars now the reason why we compound
a year so then i have that new principle plus the interest but
interest that's my new amount and then that would then generate
generate another five percent in interest so you see that becomes
percent gives me my new amount of interest and then i'd have to
that you know times that point oh five there we go and then i take
new new bit so that could potentially be a lot you know every time
add it to the principle again and then recalculate it but let's
what's really happening here so if i have this the original
and i probably don't even need the parentheses here so the
plus but remember the interest was principle times rate times
so we're doing a little bit of substitution there so the
but the interest remember that was this formula so i'll just put
factor out p so you see the things we were doing before with
then i factor out p times one plus rt but supposing t is one if t
which you know times one i really don't have to write that and
so we see a nice algebraic way to write this where i have the
then also adding it now we're not going to stop there what makes
because that is now my principle calculating the interest for that
new amount what happens when i have to calculate it for the next
original principle i did principle is what i started out with and
the rate so if i had to do it again for the next year it would be
because that's what i did to get the principle plus the interest
the rate and when we think about this in another way it really
really makes sense because we're saying that that principle times
saying you know this original principle 100 or whatever it is if
you know then that's 1.05 so you know what do i have i have a
five percent and then doing that you know that 105 percent every
that that principle times one plus the rate because if that's what
how can i simple that with an exponent and that's where time comes
time because every year then i'm doing that times one plus the
now we get from simple which is nice principle times rate times
and again good for a short term but you see on long term this is
compound interest because that accounts for every time it goes a
but then that becomes a part of that new principle and then that's
and if this was my money in the bank that's great that's good news
that i'm borrowing then the bank is going to be wanting to do this
that they get all the money that they that that they deserve you
sure that i pay that extra interest so that's where we get the
interest and then we get to this so then that's the you know
gives you you know your new amount so there we go a new amount and
we're going to talk about that new amount we're going to call it
a maybe as a variable a for amount but then it'll be annuity which
that we end up with so there we go the connection with simple and
this a little bit further when we get into the code so let's take
look at the code so we're looking at simple interest as the well
because it's good for short term and for some things that might be
but we just get principle times rate times time equals the amount
again short term because we're going to do some other things to it
and that's what we'll get to here so the principle if we just put
dollars let's say i borrowed money from the bank a thousand
always the percent the annual rate converted to a decimal and then
borrowed a thousand dollars from the bank they said okay it's five
years i'll pay it back here's the formula interest equals prt and
a hundred and fifty dollars in interest so i'd pay back that
but right away then that tells me the cost of borrowing that i
so that's going to cost me 150 dollars so then i want to find out
the new amount is just that principle plus the interest and there
the interest just like we did before and then this new amount is
so there we go and we add that that hundred and fifty plus the
now i have that new amount okay so most of the time we're going to
and then adding it to the new amount it's very rare that i'm
just the amount and not worrying about interest so here's what we
amount is that new amount is principle plus the interest and if
principle plus for one year that would be p times r times t which
it so that would be the new amount principle plus the interest so
if i divide that out i get p times one plus r and if i do the
this so p times one is is p and p times r is p r now this is going
out this p because now i have that new amount just that original p
and the rate is always going to be some decimal that it's going to
one one plus point oh five is one point oh five you can do that in
like a step and then this is what you're going to enter in the
one step that you automatically would do in your head and you're
calculator for these so that was what you would enter in the
now again this is for one year and 50 so if we go back to that
year just to show you that this works one year that'd be fifty
year then then the new amount would be 1050 so that what we're
to the principal that's compounding and compounding is exactly
principal and then calculating the percent interest from this new
happens over a few years so if my original amount is p so then the
r but now that's my new amount so so again the next year so p is
after one year i multiply times one plus r and after another year
and we'll just do this one more and again p after one year after
then that's just the same as making this an exponent p times one
because i'm multiplying this factor one plus r three times and now
that instead of having to go back and every time calculate the
then do it again you know in some loop i have one formula that
to do is add the exponent for how many years so now the annuity
r exponent t so that's 1157 now it's not an error that this is
was 1150 when i did this by hand i just you know calculated the
and then added it but that's after three years that was 1150 and
good for short term but the longer it goes the less accurate it is
i'm compounding it every year notice that's every year that i'm
next year so remember after after one year it was 1050 so then for
that five percent interest on not on a thousand but on 1050 and on
percent interest on that new amount so that's the compounding it's
the hill and accumulates more snow and gets bigger and bigger as
every time we're compounding because i'm still taking that rate
larger amount so compounded i get 1157 just that same amount over
seven dollars just because the formula was better so time is
every year but we also have a formula supposing compounding
us this more complicated formula but that's okay we see how it
of r we're doing r over n because this is happening n times per
annual rate so i have to divide it by how many times i'm
every year was the exponent the exponent becomes nt how many times
so then i'm compounding however many times as an example here i
common monthly we know recalculate compounding 12 times a year so
these parentheses gets smaller but then the exponents larger and
if this is money now if this is money you're paying back it ends
more but if this is money you're putting in the bank earning
benefit so that thousand dollars five percent for three years but
per year i use the extra parentheses for any fraction so there you
it was one plus r over n i put that in parentheses also and you
to make sure that stays because that is the whole exponent nt and
know in math we might skip the multiplying symbol because we're
python have to put that asterisk there so there's the annuity the
about this instead of just amount that's annuity and principle is
out with and annuity is the word for the amount we end up with so
monthly look at that 1161 so we go back from that simple interest
annual 1157 much better to 1161 because we're compounding it
better but first i'm going to start talking about this irrational
these very practical money in the bank things that we can
about this irrational number e and yes it's e but it's a number
the next formula all right so just a quick note about e we're
import math because e is a weird number and so when i print math
there we go and as a good estimate you can just call it 2.7 but in
want to use this whole number so that's why i want to import math
you know say 2.7 and call it good another interesting thing about
we see it's 1828 and then the 1828 repeats again that's kind of
a couple times and then it just all falls apart so math dot e use
and it's e because it's euler's number his name began with an e
logarithms and other things when he came up with this number he
mathematician that you liked euler so sometimes people call it
now if we're talking about compounding n times per year we go from
about e to being very rational well what if i just keep
we get to continuous growth so in that previous formula n could be
it 100 because we're going to do some things with this uh you know
every week you know i just made it a nice round number 100 could
and bigger number then we get the annuity becomes this formula p e
talking about e so i get this irrational number e and then the
i'll just demonstrate this so let's say n is 100 and if we do that
52 so compounding every week and then here i'm going to compare
i call the variable n times so there's the there's our other
nt and then we're going to compare that with our continuous growth
and then we're going to print it this one or this one
one so n times we remember that from before 1161 that should be
and then the continuous growth 1161.83 so it's pretty close but
1161.75 1161.83 it's pretty close but the continuous growth gives
and if n gets to be a much larger number like a thousand
you'll see it gets really close 1161.829 or 1161.834
so we see if we took it to two decimal places they actually round
and that's the idea with continuous growth you see it it's not
than this it's that as n gets larger it approaches this value so
a lot or other things beyond money in the bank or things like that
growth applications you know population increase or things like
and you know i can call it annuity i can call it the you know the
this formula so it's very useful for anything continuous growth it
throughout math and calculus some version of this comes up a lot
formula so i have this continuous growth formula if i want to
the mortgage formula and the mortgage payment formula is if i have
and that's usually a mortgage you know as an example i think this
close to the average mortgage these days 240 000 so that's a large
is 30 years that's a long amount that's a long time so for such a
such a long period of time then it actually really makes a
little bit you know every month the fact that i'm paying you know
principle reduces just a little then the next month i'm earning
principle well that really makes a difference so if we use any of
mortgage payments it's going to be a lot more than you know you
how can i afford that but when we use this more complicated
that we're paying it off gradually and looking at all that then we
amount of time what would my monthly payment be so that it'll work
paying over 30 years times 12 months that's 360 payments so i can
this amount of money after exactly 360 payments my balance is zero
given that i can figure out the payment and then we'll look at you
being a complicated formula if we want to write code for this and
to you this you don't even usually enter this into your calculator
that you can plug in the numbers here so that's what we're going
to break that down i just took the numerator that r over 12 one
numerator i made it a variable and we see r over 12 times one plus
and they did the same thing with the denominator so just the
over 12 so the exponent 12 t and then minus one separate from that
two separate variables so then the payment see i didn't forget
the capital p for principle so i'll talk about the so i'm going to
going to be a weird number and the first part is p times numerator
my mortgage payment so p times numerator divided by denominator
because that's going to be a very long decimal i'm going to round
argument and then the second one how many decimal places there we
and when we run it mortgage payment 1362 and 69 cents so given
that will make this work out that after 360 payments of this so
still accruing interest and we're still making a payment and it's
to see how that plays out we call it the amortization schedule so
that's the mortgage payment schedule and yes all these have the
means death you know kind of like you know what's what's true life
and i guess mortgage but yeah it was very morbid when people first
came up with this word but it stuck we will end this after this
so you know don't worry i don't want to leave you in the more
schedule if i take this there we go given these three things i
all this how we're going to calculate the payment all right so i'm
like what i did before so that's all the same as what we just did
is i want to have a loop to show the interest amounts and we can
that's pretty common and later on in the course we'll talk about
a loop so i'm going to set this new variable called balance and
to be that original p principle okay then i'm going to print this
month i'm going to put a tab there balance put a tab and then
the number you know what month am i talking about what's the
the interest that i'm paying for that month so here's what we have
and how many months 12 t okay so the interest is round so again
because calculating these you know it's going to be a lot of weird
two decimals dollars and cents so the interest that we're going to
again because that short term this is only for one month and then
it here in this loop so i do want simple interest it still has
p for that month times r and then t is 1 12th so i'm not just
going to divide by 12 but that's what it is this is the original
the balance is the principle for that month rate and then time is
by 12 so there we go and all that i'm going to round it to two
the interest this will still calculate the interest and i just put
of the displaying is that i only want if a is divisible by 24 you
a remain a divided by 24 if the remainder is zero then or if a is
almost the last month so these are the ones so i'm rather than
would just want to skip a few normally if i know if i put this in
schedule and i'd print out all 360 months but only for these we're
so i want a and then tab so that you know a is going to be what
range and then tab balance tab and then interest so there we go
to line up month balance interest so then after i do this so i put
first time through i want it to be the current amount and then i'm
so you see what i'm doing to increase the balance here all right
balance plus interest minus payment so you see that's what's
so we're manually compounding it the balance at that month plus
month minus the payment and then round it to two decimal places so
so we have the payment is 1362 just so we figured and then here we
balance interest so month zero we start out owing 240 000 as we
why it makes a difference you're paying 1100 in interest just for
and you know that's it it's you know it's almost the whole
at first after you do this enough times you come to terms with it
paying almost all interest at the beginning you know and then 1362
notice that only 262 is going toward the payment now we could see
but at month 24 we've paid down some things but it's probably not
you'd think like oh i'm paying so much i'd expect this balance to
just chip away at it and even then you're paying less interest but
dollars and that's you know month 24 so after two years and you
little bit less interest we do see this moving in the right
and you're paying a little bit less interest but probably not
and that's why i just wanted to skip ahead you know every two
and you know how much interest we're paying you know we take a
now you know we take and we look at this so if we have just over
borrowed 240 still a 140 but at this point now that difference we
start start building equity in in you know if this is a mortgage
the house is worth is worth a lot more than what we owe and so you
you know home equity loans that's where that comes in as you start
and you know the the value of the house is worth a certain amount
amount the difference you know you can actually borrow money
for another time so we have this and finally now it's still a lot
you know to think about wow i'm still you know look at that 20
than five hundred dollars a month just in interest you know it but
dollars a month and you know we're getting the vast majority of
point to paying off the mortgage and now when we take a look you
instead of three digits thirty thousand and then the amount of
and forty one dollars so uh i wanted to skip ahead and then just
now the balance at that point is just under what the mortgage
is this tiny amount and that would be if you know month 360 when
up being like four or five dollars more than the normal mortgage
so it works out that that that monthly payment you know using that
payment 1362 and 69 cents and that monthly payment did work out
as you know we're look at the amortization table at 360 months it
and there we go for an extra five dollars the last month i'm not
so these are you know interesting things to think about seeing how
payments applied to loans how that plays out how you're paying off
of the simple interest and then paying down this balance so this
for any large amount of money over a significant amount of time we
have to be a mortgage car payments not always because a lot of
if it was a car payment for like particularly expensive car or
of time then we might use this doesn't have to go to 30 years that
this you know paying off this debt over time so let's use
it around and have something positive retirement account
money you know this p is not money that i'm borrowing it's money
into an account and instead of owing money every month i'm going
formula for this that i'm just going to estimate this oh okay
see you'll see how this plays out and i just picked these numbers
principle is a thousand and this is just estimation here well
dollars now this is where the estimation comes in most of the time
any decent fund manager is going to be able to get you point eight
so now this is your money growing in an account this isn't you
growing in an account so if you had a thousand dollars and we
percent per year that's great and i made this time 38 years as you
just thought like age 22 till age 60 38 years so you start it put
account and then you start saving that you know from that point
you put away 350 every month in this account okay and i'm going to
annuity which i'm going to start out the original is p so now
and the percent growth so again 38 years so for a in range 12 t so
we're contributing something so notice what we're doing with this
that we already have plus the monthly contribution and then that's
one plus r over 12 because that's a monthly notice that percent
so the exponent if it was nt the exponent n would be 12 and t
so i don't need to write the exponent of one but that's where this
formula r over n to the nt but nt and is n is 12 t is one over 12
so each month then if we take this and that's why i wanted to
because i want to allow for this contribution here the annuity
we want that to happen each time and then it's going to grow so in
to grow so at the end we're going to print this out and i'm going
that'll end up being a weird decimal annuity okay so now the
but this is what we want to break this down if we're if our rate
let's say it's still earning eight percent when you start taking
interest you see and so that's annuity times the rate that's it
places but that so if i have this this amount of money that i'm
then the idea is that money now is yours in the bank or in this in
that the annual income is just that percentage rate
so take a look at this annuity here so one zero six one five nine
million dollars and if it continues to earn that eight percent the
interest is eighty four thousand dollars or almost eighty five
this money in the bank or in some investment not not in the bank
bank is going to get you this eight percent interest that makes
investment if you're you know you have this and you can contribute
constantly contributing and it's growing so at some point then you
million dollars that earns this amount of interest and i just
the earlier you start the better and the later you stop start uh
can grow even more that you could take the money out at you know
estimated did age 22 to 60 you know if you if you start as early
you know till 68 if you look at that that'd be like 50 years that
because remember this snowball so that eight percent in those
of larger and larger amounts of money and then if you get it to
of a million is more than 80 000 so that's that's the idea we want
of money that just the interest on that you know if this
on that is enough to live on and you take the interest and then
which will earn interest the next year so we want to leave you
we can use all this you know that's that's what use all all these
to you know turn that into money in the bank that's that's the
hopefully then it works out and if you have these this code you
know how much do you start out with you know keep this rate maybe
you know my fund manager is doing really well change the time
tinker with these and run it and you know see the results so you
you need to do to invest for retirement so let's look at some more
mortgage formulas here now like we were doing before i'm going to
formula as its own function so there we go uh def and then payment
pr t run it through this formula and i'll just return the payment
we can use this and all of these you know we're going to apply
know you're looking for a house you're comparing different things
to run this and there we go and i don't need to run that again now
so i'm going to do a similar function and i get something
show you this one i'm just going to define it pmt and i'm only
because i'm going to just give a set rate and time so with this
taking the input as whatever the principle is i'm going to
i'm doing this and we see these imports is because i'm going to
i'm just going to go from zero to three hundred thousand and see
that principle of course the slider shows it somewhere in the
four hundred and fifty thousand the monthly payment would be eight
and we can see how this goes up and here's something you can do
comparing different mortgages or houses you can see how does this
you know and we look at this oh two hundred and twenty one
should i buy a house it's more expensive i know my payment will go
much you see and we can look at this now that's great to see these
to see the trend maybe there's i want to graph it so notice our
case i just define my x maximum is three hundred thousand and my y
going to be plenty all these standard things you would already
points you're going to use for np dot linspace and everything
something that i don't always put in there plt dot grid just to
axe dot set x label and set y label so the x will be the amount
from zero to 300 000 and the y will be the monthly payment so now
earlier i can just use that as my y value i only need the x that
here and i'm still going to give it just a consistent rate and
the input all these are going to given the same rate and time how
monthly payment and when we run this we can see that the payment
that same rate and time and this would be realistic maybe you get
you would know your interest rate and you would know the time so
it is linear how much would it increase you know for how much
for increases in the amount borrowed well all right this is a good
get down to the numbers so it's linear i'm just going to do the
and i'm just going to pick two values you know and you know x1 and
this i just put rate and time here and i define them up here just
i'm using the same numbers consistently throughout this i feel
for the consistent example and just pick two x values calculate
values and calculate the slope formula and what we'll find so
this is you know dollars and cents so really it would go up you
of you know price increase or we can you know multiply it by a
go up six dollars you know because 5.99 i'll round up it would go
six dollars for every thousand extra dollars you borrow and now
an extra thousand that's going to be an extra six dollars in the
and you know you can put things in perspective do i like it that
thousand it's only six more dollars so we see some things we can
formulas that we we've been working with and we can define them as
use them in sliders we can graph them and finding aspects of the
and finding aspects of the graph we can do other analysis this is
building upon for our data analysis so this is all good and i want
here beyond the python i know this is almost all python but i want
do this in a spreadsheet because that will give you like that full
you also how to build that because these are some good spreadsheet
the balance here is a formula but we'll get to that in a second so
i picked this two hundred and fifty thousand that's somewhere
in the united states right now i want it to be some realistic
down payment it's going to be we want 20 percent so notice if i
up here is the formula and i just did 20 times g2 0.02 times g2 so
and i make g2 you know 300,000 instead click somewhere else then
calculate the down payment i think i do want to go back to 250,000
i feel like that's a good middle of the road number for us to use
and click and it'll adjust again now then the borrowed amount i
going to double click in this and equals g2 minus g3 actually
sometimes google will prompt you will give you that and notice
can see the borrowed amount and then up here this is the formula
minus the down payment all right so let's just say the interest
now i'm going to write the word years here i'm not going to use
but here the interest rate i will all right now monthly payment we
to this and calculate the monthly payment so we see here i just
you go six percent 30 years and i already have this so what if i
which was 200,000 even and i can just go to this borrowed amount
oh 200,000 now i could actually also just make another since i
i could actually right under here write print
payment 250 uh 200 comma 0.06 comma 30
so you see i could just actually just put this in here
output the monthly payment all right there we go 11.99 and 10
so monthly payment will be 11.99 and 10 cents
so now notice here this is just a couple of things that we can do
and 10 cents so now notice here this is just a good reference for
price down payment and everything but these notice i already had
the monthly payment and if you'll notice i have these dollar signs
some things we're going to do later i mean i don't need them over
things later we're going to drag these formulas down and it's
the row and the dollar sign will keep that the same so dollar sign
if i ever adjust this that's not going to change it's going to
that cell g4 and same with the payment that's always going to
that's what i want now the interest we've been doing all these
actually this is going to be monthly each of these is going to be
going to be a month so for monthly interest we can just do simple
balance which is a2 times the rate which is 0.06 times the time
so one month is one twelfth of a year so i'm just going to say
and this works out i mean you know that's very nice but it's not
so what i want to do is i want to add another function around here
round open parentheses and i will put you know so it rounds this
you see it'll round it to the whole number but i want to put comma
to two decimal places and this is google sheets if you you do this
have that comma and then however many decimal places even if it's
that it'll just round it to the whole number so there we go so
then my new balance equals the original balance which was a2 plus
so that's b2 minus the payment which is c2 and i want to take this
a thousand dollars in interest you know just you know just
about that and all that the paid you just took a little bit off
dollars in interest and then the payment was only 11.99 so a
to the paying down the original principle so i want to take this
it accrues interest i make a payment new balance and i want to
so that was cell d2 so i'm just going to put equals d2 here
here and here now notice if i drag this down
it changed because it's calculating the interest now based on this
times 0.06 divided divided by 12 and then here when i drag that
because i put the dollar sign in there it won't adjust anything
and we see again doing that it adjusts it for this row now
two everything here is based on row three and we got that by
hand corner you get a little tiny plus sign and this is magnified
the that thin plus sign and you click and drag that but we're
so i'm holding down shift in the arrow key to highlight the entire
over that i get that thin plus sign and i'm going to click and
amateurization table now notice my mouse is down below the bottom
that's 360 months so somewhere around there is where i'll stop
and these are all negatives so i'm going to take this highlight
then just delete them so now here this is you know after this the
so we can just make this 11.99 plus that additional dollar 13 and
decimals like that and that should be yes 10 cents negative 10
three and that should be enough to make that we're just going to
we're going to call it zero and what we have the row number is
first row as headings so three given that mortgage payment it
months you have a balance of zero so we're going to take take this
amateurization table and you know you can look through it and
the payment stays the same but what happens is the amount of
gradually because for such a large amount of money for such a long
fact that you're paying interest on just that little bit less that
and then that means that look you know that same payment a little
more of it goes to the principal so you know you're you're making
paying this off but it takes a while until see look at this i mean
to go into you know 225 months you know we're coming up on 20
payment goes to interest or less than half of your payment goes to
interesting to see that whole table and then this balance here at
amount you know supposing you come into some money and you say oh
it you know that that's the balance that's your payoff amount and
showing you the spreadsheet and how you can set this up and how we
other cells and how we can add formulas and how we can drag all
and you know mortgage mort you know it does sound like death
mort so let's do something more positive with a very similar type
i set up the same thing balance interest i'll capitalize it and
contribution and then new balance so let's look at this in a more
this was this amount that you owed that you're paying off but
account that you're adding to so i don't know let's let's start by
five thousand dollars and a lot of retirement accounts you know
you know get like eight percent interest that's pretty reasonable
so we have equals so this is column i two times zero point zero
eight percent interest and then for one month so then you know one
by 12 there we go and maybe you know we could do this we could do
i'll round it that might that might work out it'll just look nicer
to two decimal places again dollars and cents okay now monthly
you know you can contribute a few hundred dollars let's start with
start with like 200 and we're going to change that later so with
and you contribute so it's all plus equals i2 plus j2 plus k2
and then we're going to carry that around so that's l2 equals l2
l2 and we're going to do the same thing drag this down one drag
drag this down one and what we have is you know given that you
given the contribution you could always add more different times
for about the same amount of time so if we drag this down
now this being a retirement account a lot of times people will
so we don't really even have to stop at 360 let's stop with like
um there we go uh 401 because the first rose so what we have is
you know this amount that you have is 469 thousand dollars and the
this 3000 so you could easily like take that interest and then
you take that 3106 out every month and live on that and then
so you know it it you know goes from this and then back to this
back to this that's one way to do it i just want to show you so
here and say then we contribute something like you know 400
that down in a little bit and this one let's say you know 0.085 i
more optimistic on the there we go drag that down a little bit and
correct and we'll drag this down and the other thing i'm going to
longer maybe even like uh 450 months or something like that 40
so we can take this even further and you'll see that just you know
some poss some nice possibilities here all right and because look
because look at this final number here so yes that one is one
we're talking about here you know one million dollars and the
eight hundred eighty five dollars so this is something you know
take this same math and turn it around and make it positive
to and then at this point you have this money you know in this
out every month or or less and you know not have to worry about it
take that out and then you're still left with this you know more
live off the interest and you still have this every month take
to generate interest the next month and these are some of the
that you know from the other side of it you know you owe all this
but then you own this house and on the same time you're
have money that you can live off of and you know these you know
want to do with our math skills look at how we can manage manage
in life then have this you know property that has equity and you
in the bank that you can live off of and there we go you know
and seeing how you can make this work for you seeing the trends
now you might be working hard and owing a lot and not having that
many years you build things and then you have things oh i have
they've built over decades and can live off of it so that's really
some of this with the other uh python you know generating just
like these you know these are some of the ways you can make this
at the trends and hopefully this helps you make some decisions
whether it be real estate or borrowing money or other retirement
just you know some bonus and there we go we're in the home stretch
this all come together you know skills that you're building
so let's talk about exponents and logarithms so the exponential
is this two to the exponent three two to the third power equals
we've been doing this so far in algebra then logarithm is the same
so this same information the log base two of eight equals three so
exponent that's what we want to know that's what we want to know
far and in most calculators you know two to the third no problem i
calculator in python they don't even have to import anything but
and i know what i often call the result if i know the base i know
is what i don't know then that sometimes becomes a problem
nicely like this works out but supposing you know it wasn't a nice
even nice exponent like three supposing you know two to what
it's going to be some weird decimal but how do i how do i get that
to appreciate that you know uh john napier you know spent like
20 years of his life figuring this out and making tables and now
button on the calculator and we're going to look at also how to
logarithms we do have to import something but you know we'll
than spending 20 years years of your life figuring this out so if
um you know the the base is always going to be whatever you know
what i call the base so if i have you know log base two of eight
now what's interesting is our count in our calculators we you know
you'll see a log button now if i have the log if i just say the
i don't see any number there if i don't see a number then it's
and we call that the common log because our number system is base
write that and so the log of a hundred is two because 10 to the
and we're going to use this a lot of times for working with
converting decimals so that you know that's that's where a lot of
the common log and then i might even if i'm doing things like
the floor function because if you know what's the log uh you know
two point something but then for converting it to scientific
the two because then that tells me to move the decimal place too
1.5 times 10 to the second you see you know different things that
converting this for scientific notation all right other
that exponents and logarithms they're inverses of each other so if
um if i have the log base two of two to the third then or actually
a definite number i'm going to call this x because then anytime
the log of the exponent anytime you have a function of its inverse
now notice then what we're saying here the log base two so two to
x oh x is the exponent you know makes sense and the same type of
to the log base two of x exponent same thing that's exponent and
look at this log base two of x so it's two to what exponent gets
want the exponent two to what exponent gets me x and whatever the
am and then in fact taking two to that exponent so i would end up
we're going to use these inverses and this is where it becomes
for whatever base i have if i'm solving something if i have three
that doesn't work out nicely if it was 27 x is three that's nice
on the calculator what am i going to put on the calculator well
x equals something well if it's three to the x then if i take the
of this three to the x and then on the other side it's going to be
so in algebra in the things you know i do the same thing to both
do well one of the things i can do to both sides is take the log
same base so if i take the log and i pick base three because of
down to x and then over here i have the log base three of 25 which
calculator and we'll see in the code you know we're going to
able to do this you know no problem on the calculator or in the
thing is if you're on a calculator or you know you want to do
i could just do the common log for this it actually works out also
divided by the log of three so the log of this divided by the log
use common log or whatever i'd want for that so you know that's
you know what another way that like that works so change of base
in a situation where you don't have the ability to do the log of
you can use whatever logarithm you have and do this so that's
we use that inverse property when we're solving and that comes up
to look at things you know things that are growing exponentially
sometimes it's you know radioactive decay for dating carbon all
in this situation exponent my unknowns in the exponent and so i
figure that out the other log is going to be the so we have all
the common log which is base 10 but then i also have the natural
and if i was writing this it's i'm going to i'm going to write it
the logarithm functions in python they actually if i just say log
not base 10 so that that's really interesting in python the
another base there but if i was writing it out it's l n for
natural log of of anything so the natural log means that it's base
e is about equal to that 2.71828 1828 and then after that it's
it just that pattern stops so oh 2.71828 so he's about 2.71828
for a lot of continuous growth formulas so if i have you know the
well then my answer is going to be you know about one it's going
it's like 0.99 or something like that you know 0.99 and i can you
for for some other things and we'll see some of the applications
code but that's where if i have base e so if if it's base e i just
i can just write log and if it's any other base and the bases we
whole numbers but if it's any other base then i'm just going to
so okay so we take a look at this we'll see how we can actually
in the code and that's going to be pretty useful for some of the
so let's take a look at the code so when using logarithms in
library and now we have math dot log there we go math dot log and
and then the base so this is math dot log of 10 000 base 10 so
four this works out nicely for things that we know are going to be
show you that python weirdness sometimes even when you think it's
math dot log of a thousand base 10 so i expect this to be exactly
it gives me this long decimal so any of these even when you think
the way that this works behind the scenes you might want to just
so i'm going to round all this math dot log of a thousand base 10
to four decimal places so you just might want to build build that
get that answer and notice i still said four decimal places but
not rounding not needing decimal places it didn't have to give me
there we go so that's just the usefulness of it that it's just
in there all right so that said i have a few of these that i don't
just to show you what the exact answer might be so if i have base
and then we're going to do math dot log in this case 16 base 2 so
four and i don't have the log in there so if i have something like
rounding so you see it'll give you all that if you need these
for something it will give you that but there you go just whatever
natural log i'm going to import math again and notice here i can
and if i don't give it that second argument of what the base is
and e is about 2.7 so if we we do this we see you know it gives it
want to show you is as we were talking about before uh so math dot
math dot e is going to be the most exact you know it'll give you
have to just you know guess at it but also e to the fourth then
so if i have e to the fourth and then i take the log which is the
four because the log of that exponent or if i have e to the third
i use that math dot e to get the most exact uh approximation of e
argument then it will cancel out and that'll that'll work out the
you know 10 to the fifth and then log you know base 10 you know
just just to show you this all right so other good uses of log or
answering the question how long will it take for an investment to
and i still wanted to put the algebra in here so if we have our
so i have p and then i have the annuity what number p what what it
what number it ends up so if it's doubling then whatever i have
whatever the number is so i can divide both sides by p and then i
so as we were looking before about getting to exponents if my
it what's my base and then i'm going to take that log of both
take the natural log so on the left i have the natural log of two
of e to the rt as we just saw is going to be that exponent so
i'll take natural log and then they will cancel out the function
want to solve for t now i have rt divide by r so i would have this
by r gives me how long it would take money to double so we can
just define r as the rate here you know two percent you know sort
natural log of two divided by the rate so i am going to round this
argument there log two and divided by r and also the rounding is
whole number there we go and we get it to be 35 years so if
35 years from now it'll be double and like i said as a low
whatever now 35 years from now it'll be about double that price so
you know some investment you know oh nine you know nine percent
to be doing okay i put money in this investment how long will it
in this case eight years so there we go so you know some people
for what they invest in and there we go answering that question
i want to show you this pattern of graphing the exponent and the
all the usual imports for any graph we're going to do all the
dimensions here and we've done this before when we use numpy i
points here because then i'm going to create my numpy array np dot
using this many points so there's my array now for this i also
array specifically because my x min i don't want it to go down to
at 0.01 and we'll see that in a second and then again set up all
i'm going to graph this first line here y1 equals math dot e to
i imported math just for this using math dot e so if i'm graphing
and then line two so then if it's e to the x i want to do the
and i didn't use the math one here i wanted to use the np dot log
graphing so numpy has log built in also so i want to use that
with with the numpy array and that's this is why i wanted x2 as my
can't be zero and they can't be negative so i didn't this actually
but it would still graph it just with that error and i didn't feel
that other array starting at 0.01 so there we go so now i have e
it's just y equals x all right so this is what this looks like and
upward that's the exponential function and going to the left it
it just gets really really close beyond what this display can show
and then this orange line that logarithm it the x value can't be
has this curve to it as x gets bigger this increases but it not so
goes on and on and then the green line is y equals x so if it
each other across that line that's true like any inverse functions
the line y equals x so kind of cool how that works out so we see
e to the x natural log of x and just as a slight comparison i
two to the x and i'm going to use this and comment out this other
have two to the x all right there you go two exponent x and then
and again i'm going to use numpy and you see numpy's log instead
have different functions so this is so log is natural log log two
there's log 10 so those are the main ones you'd you'd want to be
gonna have log two here and then the line y equals x so if i run
different because two is not as big as 2.7 but very similar and
drawing i i wouldn't be able to draw the subtle differences so i
look the same you know exponential logarithmic y equals x there we
good good estimates here all right we can also use logs for
it print out 3.2 times 10 to the fifth now i wrote that in
with with all the zeros here and here i have it as a negative
second there we go and you might be wondering about that comment
why that's an important thing and there we go uh we see the output
three gets weird very interesting because the exponent of positive
know got a little weird too and you see just the way it works
we would think that it would stop there and that'd be fine but it
and then a five at the end unnecessary but as i was mentioning
will solve a lot of these problems so you know i just use this
so i have this 10 4.5 times 10 to the negative four and i'm going
places so if i have a negative exponent let's say negative four
decimal places and then that gives all of these because it'd be
place to show that so you see rounding rounding again works out
negative five and greater it forces the scientific notation so as
going to print this out i already have it in scientific notation i
decimal places doesn't matter the output python wants to put in
this e is not e 2.7 but it's 4.5 times 10 to this exponent so
calculators use that notation also we can convert something to
if i take this so i want to get the number of decimal places so if
variable a so if i take the log of a and base 10 so this one i'm
take the log but since it's not 0.001 it's not going to work out
it's going to be like one point you know it's going to be like uh
is going to be four point something so that's why i want to do
exponent i want to chop off all the the extra decimals in my
that the floor of that is going to be the exponent so that's
four and then if i take n i'm going to round that 10 divided by
works for larger numbers too but if i take that and then round it
two decimal places that's fine that's n i could stop there but i
in case there's rounding errors because it could work out
greater than 10 you know that that happens and so in that case
i still get true scientific notation one number than the decimal
if it's greater than i'm going to increase the exponent now for
point zero zero zero five and there we go it gives you point zero
ten to the negative four and then this should work for all kinds
converting it to scientific notation if you wanted to so these are
logarithms you know we can see the graph that's pretty interesting
the applications the solving sometimes if my unknowns in the
to and from scientific notation so these are a few applications of
you will find even more so you can make use of make use of this
here we have the foundational math three certification three and
going to make a copy first of all and work through this whole
google drive and then from your copy we'll do first step like
testing library and later on in this unit or the next unit we'll
and how you can set up your own virtual your own library hosted on
into whatever notebooks you want so you know as you can see here
whatever notebooks you want so you know as we get through this
of setting it up and then you'll learn how to set up all these
comments here you know install requests here's the library and
library take it uh as as a new file locally here uh behind the
it and it's imported there we go and this last thing says that yes
on to the next step there we go and remember the runtime run uh it
consecutively at the most or about a half hour of inactivity so
you know working on part of this you leave come back then you go
so we were looking a lot of into graphing before now we're going
i have let's say y is greater than or equal to 2x well if i have
do i shade that well we have this argument here fill between and
so we're going to go here import matplot library and import numpy
and we're going to set our window like we were doing before how
linspace give our points setting up the graph all this is very
fancy put a title on there so we have the plot title y1 just like
i was graphing this just as a line we see all the similarities
and remember this we have plot these two and then we have this
we had this third argument so if you're working through this and
watching this video maybe hopefully you already did work through
you know double checking anything you did or if you want any
we have the second arguments are the fill between so this one
fill between so we still have one x value and the y values are
zero and i'm just going to run this to show you you see it fills
that doesn't matter you know that's not a consistent you know over
is up top and over on the right it's down to zero but thinking
oh what if i just change that to if i want to shade above what if
and then we're always shading above between that line and the
below you can change it to y min and there we go and when we do
so part two well we had this one is a nice solid line and remember
to but what if i wanted you know not that solid line so we have
here we know the logic of this so now if i have y min now that's
below and this is the only thing we're going to change if i have
gives me a line until i do the fill between but what if i wanted
so we see you know see if i have b dash dash r dash dash gives it
and we run this so now we see and sometimes i'll do that i'll make
stands out if i made the blue just blend in so now we know this
and there we go yes and knowing now that we can make some lines
you can define these lines we can make art for example we can do
fill between two different graphs two different functions oh that
this defaulted to notice i didn't even define the color blue here
but i can define that face color what color do i want to do i want
so if you know like a lot of your basic colors you actually can
that you know i want to be green put it in green in quotes single
color names this will work out so that'll work so the directions
and then reverse the order so we see here like before here's the
plotting and remember we defined the x value up here once so
i'm not worried about making a particular line so two arguments
between and see what i have x y1 and between that and 10 or i
max but that's fine and then i add the other argument face color
and fill between now notice between y2 and y1 so you know we can
you know between other values that's this is this will come up
you can define your lines and then fill between these lines i mean
so then change this you know we have this color and same thing all
you know this line y3 and i'm going to fill between y3 and y2 next
function fill between y4 and y3 and so when we run this see that
there up to the top and then i did not decide to have another one
just left it here so if we take this and reverse the colors so
colors and make the first one blue there we go and we'll reverse
red at the end so the next one will be green and the next one will
be red there we go so now we have this and we see when we run it
so there we go interesting things you can do and if you were
whatever formulas you want remember you know we were looking at
you know quadratic you know uh exponential functions so if you
and you can just define that you want it to be between something
where i define this linspace here once so that's the reason why
but you could always for each of them you could define lines you
within certain values and you can make all kinds of shapes and
with other graphing i kept these axis lines but you could always
you just keep your window size but then you could always eliminate
again you can get creative with this make some different art all
looking further into factoring into representing equations so
mono is one and then it actually overlaps n o m is name that exact
and then i al just makes it a noun so one thing one term so each
and variable and an exponent we don't think about that all the
definitely i see a negative sign i see the coefficients three x to
but if i have you know all of these the term x also has that so
first power just things to think about because that really comes
that we do with factoring etc even even a constant like five is
five x to the zero because x to the zero is one and this will help
each of these you can have a monomial and just make sure that you
sometimes these values might be one or zero and you might not
now this is just a very interesting within simp i we have eq which
and you see how this equation is eq and then in parentheses i'm
and then what's on the right so i define it as an equation and
by a comma so you see what we have here so just showing you that
could use this within simp i for some other things that you might
of this course you know if you wanted to make sure you have a nice
up eq you know use your variables that you already have and you
symbol here so we could do this and then just display it and then
and so we have monomials one thing binomial bi is two trinomial
is three and after that we kind of stop counting so polynomial is
three and we'll usually put them in order so we take x as the
the highest exponent and if we want to graph this then it would be
so there we go here's your example and it continued on to the next
know this i this is the normal standard standard form setup so you
coefficients and then display them and so there's what we have
so we're going to use this display and we're also going to use
to import everything from simpy so now we have these symbols and
i do want to cast it as an integer though i mean realistically the
integers so there's our coefficient and a and b continue to prompt
you can do is you can copy this and make this c input coefficient
all right so we've done that and now we want to display the full
display ax to the third bx squared and then we do the rest plus c
plus d and notice we you might have remembered this from before
i just put these right next to each other ax means i'm multiplying
notation i have to put that multiplying in there so it is ax to
go now we have this this is great we have this in python notation
we want to display this in a nice way oh well i have to convert
way we're going to you know to display math terminal math formulas
i'm going to convert that python to there you go so if we have
so you see we can take this and convert it that way you have all
thinking ahead we're building things that you can use you have all
coefficients you could do other math to this here and then maybe
this this formula in a nice way so there we go that's what we have
so this is going through so interactive polynomial so now we're
this you know here's well quadratic but there we go and given this
we're going to adjust each of these coefficients so again in doing
certification notebook you should see that this is coming up you
and hopefully you've already worked through this and you know
you were stuck on or if you forgot so remember we were doing
and we're going to bring in the interactive from the widgets there
and remember these the function of a b and so for this one we're
third slider so there we go so my function needs to include c
because i need these three inputs great and then all the rest of
ax squared plus bx i have to add this plus c
c and so that will show the plot and then we want to make all
i'm going to run this function a b i just need c
so we can just copy that comma
so now we will have three sliders a b and c and we have the
display the interactive plot so there we go so that's how we can
you know using the same thing you can modify this to have four
looks like nothing because everything is zeroed out but as soon as
then we have a quadratic you know negative all right so that's
and it's always interesting to move these and see what this does
so you can tinker with this and see remember that just moves it up
there we go so you can take these and you can tinker with you know
code test pass but these notebooks you can always tinker with
you know you've learned that step you can go back in there and
see let's see what it looks like so now we're going to do
our exponential function y equals a times b to the x and there we
zero then we'll have an upward or as long as a is greater than one
thing as long as b is greater than one we'll curve upward all
some of the exponential functions the so what we're going to do is
see the sliders and then change the slider so that a actually does
instead of positive so here we have all these importing same
minimum and y maximum a lot bigger things grow exponentially so
decent graph here we just have a and b and you see one to nine we
so when we run this we're just going to see what this looks like
either one you see as i increase this it gets to be steeper
but we see the general shape of this it just gets to be steeper
it just gets to be steeper and then if i change a
i'll even make this low because it don't it still will be
so that's that's really all these you know they kind of do the
thing maybe b has a little more of an effect but then you see it's
upward curve and then as the x values get negative this really
get it's beyond what the resolution of any computer screen could
in you know it looks like it doesn't touch and then it looks like
then it doesn't so you know that's the general trend so if we make
need to do one more thing because this interactive graph takes
net making it negative negative one is not the lowest we have to
is the low value and negative one is the high value remember
we don't switch those also then we would get an error so we get
see just making the a value negative would make the whole graph go
b to the x would be positive still so then a being negative there
and just a note making b negative i'm not going to even worry
we did that it works for integer values of the exponent but since
it would be integer it would be work it would work and it would be
an even exponent negative if it's an odd exponent and it would go
those in between values because that would be mathematically
would actually be imaginary they wouldn't they would not
sometimes if we had you know some of them would and it would just
not even going to mess with that changing b to negative it just
anything but behind the scenes that's what's happening it works
doesn't work out nicely for others and you know a graph would be a
that does work out nicely percent increase so hopefully you
working through it in the previous unit but then we have you know
and if i were to graph this so we have a equals p times one plus r
and a is annuity and that would be the y value if you were
p and you would know r so t would be time in years but that would
graphing it and so we have all this yes p is the principal the
rate converted to a decimal and t is time in years and just the
capitalized so it's just interesting in in my variables i kept
times you'll see that written you know they're lowercase but p
um all right so you have your starting amount so you can prompt
worry about changing the code well we are going to change this
amount as input and converting all these to float numbers so you
numbers percentage rate converted to a decimal and how many years
going to take this equation and put it down here in python terms
gotten from here so p times and remember i have to put the times
one plus the rate and all that to the exponent of time and there
equation to to python and then we'll print out the annuity so when
one thousand just take these nice even numbers all right and we
that'd be five percent and how many years then let's see uh let's
and i didn't worry about putting in another function around this
but there you go to two decimal places this is what the annuity
percent for seven years and then we have percent decrease very
subtracting inside the parentheses because it's one minus three
does happen we have car value values of cars or some other
certain percentage rate every year the decay of some elements so
certain elements like carbon 14 that are very predictable so that
knowing how much that we can measure how much that is we can
the age of something some sales discounts maybe there's something
at a percentage you know every week if it's not sold so you have
and notice we're going to do same thing prompt for pr and t and
very similar p times and then in parentheses one minus r close the
so there we go and we see you know the jupyter notebook the colab
us tool tips and advice on what variable and everything so there
run it all right so there you go so let's just say i had my you
that uh decreases at 0.09 which might be the you know rate of
how many years will decrease you know let's just say 10
so there you go that twenty thousand car twenty thousand dollar
depreciation is nine percent so it loses nine percent of its value
then ten years later that car is worth seventy seven hundred
that might be the case i mean you know this is not uh don't quote
for the sake of practicing it that that rate's probably realistic
all right so now we have compound interest which is very much like
but we're taking it you know we could use compound interest we
before if it's compounded once a year so now we have this formula
but it's r divided by n and then the exponent is nt so if it was
and is one so that doesn't that goes back to that formula we were
but where n is multiple times per year you know this is the
and remember that that's really and that's why we wanted for any
wanted to convert it to that formula that it's something that's a
easily adjust the rate of decrease that's why we wanted to convert
and we can then easily adjust this for how many years something
and in this case now we had the other twist also then for how many
every year i mean n being 12 that's pretty common you know a lot
you know they calculate things you know once a month so we're
amount all the rest very similar and then we're going to add this
compounded so using this formula then we'll do p times and in
r over n i'd rather use extra parentheses just to make sure that
uh r divided by n and all that to the
so you see r over n in the extra parentheses to the nt but again
in parentheses n times t in parentheses so that way it stays
python might not but i want to make sure it doesn't accidentally
you know well then multiply by t so there we go p times one plus r
and that's going to give us our annuity so
just to be interesting let's use the same one we did two steps ago
converted to a decimal and we were saying that that was at 5.05
and and 12 is pretty common but i'm going to say 52 let's say it
you know every every week all year
here so what do we get 14 18 and 82 cents and let's just quick go
increase 1407 and 10 cents so look at that just that little amount
made us another 11 because it was compounded that often it's a
you have that little bit extra advantage this is money growing and
percent for that little bit more time you know gets you a few more
well okay 52 then maybe 365 would give you a little bit more
quick do that so remember that was 1418 and if we did this so that
we're going to do the same 0.05 the same seven years but then this
every day so you see 1419 it gave you another dollar so compared
made about 11 more dollars doing this every week but from every
one more dollar so there is a point to where it doesn't really get
we start thinking about well okay can I compound it multiple times
into continuous growth and continuous growth if i use that formula
times a day if i compounded that like three times a day and who
make n like an even thousand it starts approaching this other
recap so there you go that's you know money compounding annually
increase but we take it as annually and then n times per year we
n gets to be really big like i said like a thousand or something
formula pe to the rt and this is useful because as we see later
what the rate or the time would be if i know these other values so
complicated to i actually think this is a little bit easier
e is not just a random variable e is this constant equal to about
through that twice the next time it's not exact so it's not just
that would make it even easier but it actually after that second
different okay so we give the code that we're already going to
we're going to add one more import statement we're going to import
math.e you know you don't have to worry about typing in this
to take it to even more decimal places so we have the same thing
there you go time and that can be an integer that doesn't have to
and is going to be an integer because you can you can't like maybe
do you compound it you can't say like oh one time i kind of like
okay so now we're going to use these these same formulas we did
annual so that's going to be p times times one plus r exponent t
and then this one is going to be p times one plus the extra
exponent of nt so these are those two formulas and now this one
math.e so that's going to be p times math.e to the exponent of r
so there we go we see pe to the rt
t and now we have these three so we can prompt and let's compare
compounded n times per year i'm going to put an extra space in
so let's take something here and let's just say a principle of
and time and let's just say you know 15 years n and we only need
but let's say n is a normal 12 so given this compounded annually
2632 compounded 12 times a year 26,995 so wow that made you know
just by compounding it but look at that compounded continuously
see from here from once a year to multiple times we're talking
but then from that to compounding it continuously you know
up to about 700 more and it kind of evens out that oh and this one
it gave this error because i used the parentheses so if you're
you know these errors messages are supposed to be hints just to
parentheses and that is okay because python does no word of
it should give us not the error so there we go and should give us
so 11,000 rate 0.06 time 15 years and and we said it was 12 so we
message saying you know maybe i'll go in and change that that the
right so there we go prompting once and comparing these three
interest so now some of this comes in where we have you know some
often you know something you might be contributing to for
value so we have any of these formulas but we also contribute
will say month monthly that's that's kind of a normal normal thing
about like all the different values that that could be okay so we
to increase by a percentage and we're using just that simple
principal times rate times time so that is just simple interest
and for one month t equals one over 12 because time in years but
by 12 so here if i have this we can set up a loop here so prt but
ask for the monthly contribution all right now this annuity at the
have i have this i have this amount done so we'll keep that but
that we're going to keep updating so somebody said time in years
12 times t so monthly contributions for this long for a and range
t and now let's see we're just going to say first of all the
all right so now that annuity value is greater and then now we
so that's why simple interest is just the interest equals annuity
time and then times one over 12 and i'm just going to say divide
in principle times rate times time and then 1 12 is divided by 12
and now again i'm going to update annuity annuity equals annuity
annuity plus interest and because i'm making this a loop then you
are useful for not having to do a loop but we also wanted to add
and then there we go so you know we have a few things going on in
the loop it's going to go through and each time you know add the
percentage for that little bit of time you know now update annuity
this so starting amount maybe we can say 5 000 and annual
for you know some uh you know retirement account 0.08 and then
some of the things you might contribute and then have it grow for
like long amount of time 35 years there we go monthly contribution
we go so that's that's what we have you start out and then every
and you know we hope it's growing at that rate
so given this notice how notice what this number is that's a
is and to get some of these the the rate it it changes that's
it's a reasonable very reasonable estimate so putting money away
put five thousand dollars away and some good account for as eight
then each you know each paycheck you're contributing contributing
with a million dollars there you go things to think about that you
that you can put away this little bit forget about it for 35 years
and you know have this because if it's earning if it still is
estimate eight percent of that million is eighty thousand dollars
thousand dollars interest you can live on that and it still has
keep generating more interest so there you go
okay so we go from the positive saving money and having a million
payments and yes more like the word for death somebody originally
this death payment but nonetheless mortgage for any large amount
of time those other percent increase formulas won't quite do it
paying a lot more than is reasonable so this is the much more
that's the value of you know setting these up and writing the code
remember this formula or you know plug the numbers in every time
we were doing before pr and t and figure out what your monthly
so given that some large some huge amount of money and how banks
um something else but knowing how much you're going to borrow and
it through this formula and figure out what would your monthly
useful you and again this applies to mortgage or possibly car
large enough sum and a long enough time that this is a much better
this is the formula and again p is principal r is rate t is time
but n would be 12 each time so i just put 12 in there so it kind
formula but n is 12 each time you know there's no other setup you
payments or yearly no it's it's always monthly all right there we
so now i gave you a hint to do this use other variables i like
look at this r over 12 comes up a few times so you know we can
um there you go r over 12 is uh you know multiplier or if you
other variables you can do this there we go and since i don't have
um i could have i might have like just like math n for numerator
and so the payment would be n divided by d because that just might
um and then it would be p times n divided by d so i could have
r over 12 times and then in parentheses one over r over 12
oh one oh sorry one plus r over 12
12 and all that to the exponent in parentheses 12 times t
so r over 12 times one plus r over 12 to the exponent 12 t there
not bad and then i can have the denominator equals so one plus r
12 put up with some parentheses 12 t and now when i subtract one
you see then that's definitely not a part of that
so yeah and again you could add other variables you can make r
something like that you can make one plus r over 12 its own
do that i feel i felt like this wasn't that bad so but breaking up
and then payment times numerator over denominator
so we take a look at this and the amount borrowed we could just
uh annual percentage rate 0.07 you know some of the rates have
to say that for now and number of years 30 is pretty common and so
there we go so 1330 and change and this helps because then you say
the cost of the house and i have a down payment you know you get
that's one thing okay but what's really going to make the
your monthly payment be that's the important thing and you know
whatever your income is the monthly payment should be for mortgage
fourth of your income or less so just to remember you know if
month you should be making at least four times that or if you're
house because sometimes you might say oh yeah i'm making more than
end up being house poor yes you can afford your your mortgage
else all right so let's go on to exponents and logarithms with
they're inverse functions they're the same information rearranged
here two to the fourth power equals 16 so there you go two base
and then the log base two of 16 equals four there we go both of
rearranged and that's what logarithms are you know picture
sign oh two to the fourth power i know how to do that plug that
it's the exponent you don't know the log base two of 16 the answer
exponent gets me to that so uh this guy john napier like 400 years
400 years ago he realized that that was a missing piece that that
wanted to know the exponent for different things and he spent like
developing this and it was you know very useful you know the
you could like look them up now we have this at the benefit of you
and we're going to take it one more we're going to even write the
couple numbers and it'll calculate it so if you use the math
numpy library that's another way but if you use the math library
and then the arguments are you know the log of what so 16 and then
so there we go and if you don't have that first argument or if you
if you just say the log of 16 it takes it as base e but we'll get
we go the log base two of 16 so here's the code we're going to
always call the the exponent the result just because it reminds me
what i want so there we go so or you know that's the the result of
i had somebody input the base and we're going to input cast as a
but usually it's an integer and the result and cast that as a
change the next line okay math dot log and we were just saying
and it'll import this for it and it'll do this for you so that's
and we'll run it and this should check it for you there we go base
three result 81 so it should return four there we go nice you
in your head but if you have you know base you know three to what
you can do that in your head that's four but this is useful three
or gets you 85 you know when it becomes some weird decimal all
talked about e so uh this is the this is another use of a
if you have this formula annuity equals pe to the rt there we go
how long it will take for something to double and you'll see the
you know whatever i start out with p the annuity needs to be
then whatever p is and annuity is twice then i could cancel it out
so it simplifies to this and then now one of the many situations i
exponent well i have base e so math terms i would say natural log
the natural log of two on the left and the natural log of e to the
the natural log of e to the rt because that says e the natural log
this so e to what exponent gets me e to the rt well it's obviously
we know that take the natural log of both sides now we're in this
of two good thing i have a calculator to do this and then if i
double if i know the rate then i would just divide by the rate and
that math dot log and you see no other argument necessary if i
as what base it is it takes it as base e natural log so there we
rate as a decimal and for this one i just put the end just it's
the input comes in as a new line on a new line and once the person
just math dot log of two divided by r is time and we'll print out
this is pretty useful so you can run this now this one remember
let's say i have some investment growing at eight percent and it
six six years so some of the you know you might say all right if
percent and we can even round this down to eight and a half and
okay well eight and a half years it'll double 17 years it'll
and you know you could use this to estimate some outcomes all
10 it's the common log if you were writing this in math notation
log so uh with without the little number because then you know if
then oh we'll take it as base 10 because that's our number system
we're going to be using when we want to have you know how many
things for scientific notation so in the code you see we'll just
so you see uh if i don't say the base it's e but 10 even though
base there we go so if we have this and our number with several
and this one i just separated into two lines to show you can do
you know cast it as n the other reason to put this into two lines
line over here maybe even before writing python you know you might
you only want the lines to be so long you don't have to scroll
a design decision if i continued beyond this line it would still
that code but just as a convention for writing python code we
80 characters brings it over to that line so there we go i have
want to go further on that line so i just made it a separate line
all right now we have the round the code so this one we have math
take the log of that but i'm not gonna round but instead of
of this because i don't want the decimals i don't i don't want to
and i would just you know drop the decimals math dot floor that's
and that's actually what what we really want and this is a weird
exactly three it sometimes doesn't give you the answer you want i
python quirk so just bonus insight here after doing this enough
if statement here all right and we're going to print the exponent
there we go several digits so if i have point you know zero zero
there we go and if we remove the math dot four function
then it will just give us it'll be you know negative four point
just do that there we go so you can see and i'll just to compare
zero zero five all right and that's it now notice in positive
something or three if this was positive three point something and
it'd be down to three but with negative numbers the floor from
floor of that is negative four so just interesting insight and
because if you've gone through the the foundational math three and
on something you're what we want some other insight into some of
this helps all right now all that you know we can use these
something to double you know things like this uh number of decimal
exp for exponent because well first of all that's what we're
but also that leads to scientific notation you know how can i
numbers without all those zeros so if i had like 45 million oh but
to the seventh or point zero zero zero all these could be 4.5
and there we go so it's always n times 10 to an exponent and n is
so that's what we want you know because 4.5 that's i want that one
that that's the true scientific notation now this is just changing
not actually writing code this is determine the value by just by
just to see so you know as we count so how many decimal place how
five six seven eight nine ten eleven because it has to be down to
one is 1.56 that's where the decimal would go and a2 would be 11
out a that that is a1 times 10 to a2 so then we'll do this for
so the decimal point would be there so then it's yeah so then we
five six seven eight nine ten so it would be 4.13 and we have to
so it'd be to the negative 10 and so then that would print b is
there we go and we run it there we go now
now this one works displays nicely this one how we want to display
automatically and this is fine you know you go on the next step
this one a positive 11th power fine it didn't see a reason to
the python notation 4.13 e negative 10 so and this is not the same
so times 10 to the negative 10 so there we go in this you know
watching this it's you know illustrating like why there's some of
so we can use these logs for scientific notation because if i want
this to scientific notation in an easy way so what do i do so i
together the things we did in the last two exercises so for a i'm
of the log of a base 10 there we go and now i'm going to round it
so it was a i called it x1 for exponent one and so if i have this
and it rounds it to two decimal places so if that's the if that's
multiply this times 10 to the negative x1 and it's going to print
i'll just show you the code and then we'll run it and you'll see
what i want x2 and i want to show you that this actually works for
so if we have so but this one i want this for b so take the log of
and if i have this then i'm going to round that so i'm going to
again referencing b this time
to there we go so it's what exponent got me there but then when i
then that will divide it out that's why it's that that's why it
because i want to divide it out to get that early number there all
and this just took those so you see we get a is 2.34 times 10 to
and b is 1.23 times 10 to the 13th
so pretty cool how you could just take this and whether i wanted
a decimal so a negative exponent or a huge number with the
this this works take the log base 10 and the floor of that and
that's how we get n1 you know then we're then multiplying it by
and we can display so this way now you have it you can have a code
to scientific notation pretty cool
and that's what we get into step 19 there we go now this one very
before and we're just added one more thing of entering a number to
notation so see this is where you can make it as your calculator
this and it works either way i'll copy this code that we had from
i don't need the number ones because i'm only doing one thing
right and in that case if we want to print you see i even left
so we can reuse this and this is the key with copying and reusing
be aware to notice these little things if you just copy and paste
there there might be a little subtle things that don't line up you
good you have to understand the code well enough to know these
oh okay i needed to delete the ones here all around and you know
copy paste with the follow-up editing now that works and see what
standalone uh you know input you didn't have to like define the
and there you go enter in whatever number all right so one two
three there we go there we go
two three i got to one point two three ah look at this it see as i
i didn't delete the one there and that variable was still in in
so it gave me this you know exponent that i was not expecting one
all right pretty good so anything that you have now now we have
and then later on what we're going to do is and then maybe i'll
put all of this code within one function and so then now you can
convert to scientific notation and all this code is within that
then that function we can use wherever all right so let's go on to
graphing exponents and logarithms so just connecting with the math
putting the adjective first natural log if i was just writing it
and that would be base e and so comparing y equals e to the x and
those two are the inverse functions and mirrored over the line y
we'll see these and then we'll see the line y equals x so we were
library if i just want to calculate a logarithm i'll use math.log
using numpy and we're using the linspace function to create an
graph so i have to keep with numpy which i usually import as np so
you see if i want to do one thing yeah that works if i'm using the
i'm using np.log and np has it slightly different np has np.log 10
base 2 and if i just do np.log it's going to be base e
other base because we have the change of base formula which i'll
we go so we have the positive x values now e to the if i was
all my x values whatever i want but when i do natural log then the
because remember they're inverses so in this case e to whatever
zero as the inverse here the x value will never be zero so when i
familiar from other graphing we might have done i'm going to
minimum maximum you know based on here what i did here that's fine
log i need i'm going to use a different linspace i won't do zero
tiny number 0.001 and that should be enough to illustrate this
so i'm graphing these i'll use x1 is my array of x values and
and then within that range i want a thousand points i mean you'll
smooth graph even if you don't have a thousand points all right
and i'll just write the y value here instead of separating it out
and then that to the to that exponent there we go and i'll make
the red line for y equals x then x1 and we see if i have this x1 i
it's y equals x so i don't need to define a new y value which i
and here now for my log y equals log of x i'll do this linspace
all right so we're just going to run this and then change it so we
and there we go so we have the blue line e to the x exponential
y equals x or y equals the log of x and there we go and this works
there are mirror images across the line y equals x but this there
it illustrates it nicely all right now change the blue line and
make these log base two so here instead of math dot e i'm going to
you know that's fine and this one instead of np dot log i'll do np
now we're not going to notice that much of a difference here
i went from a base of 2.7 to a base of 2 but there we go that's
one i don't want to include some applications here if you have the
as a decimal number that's really where the ph comes in so
so the way this this works it's the negative log of the hydrogen
so if we have 0.007 as scientific notation that would be seven
which would be a ph of three and then we see that as we got more
you know a really tiny decimal number then that would be ten to
know ten to the negative ten you know really tiny number and that
ten to the negative ten would be a ph of ten you know we get the
just taking this and if you knew the hydrogen concentration i was
in as like going into the chemistry and finding hydrogen
the those of you that want to uh you know pursue the chemistry
actually get you know various uh hydrogen concentrations of
work it out from there okay but nonetheless so what we want to do
concentration so it's the negative log and for this one i will use
going to make this negative math dot uh log and i'm going to log
ten there we go so that's that's really it and now that log i get
and what do i want to do i want the ceiling so i'll do math dot
perfect all right so there we go when we run this end of the
and what if i put your point two three four and there you go and
i would take this as we we look at this and yeah this is the
is and then do the math dot ceiling so that's what we'll do we'll
and these are the things that i wanted to put in here as you know
we see why this this ended up being wrong because then it gave a
putting the math dot ceiling in the wrong spot
all right so i'll do the same same one here point
i'll put a one that's okay there we go now that gives it a ph of
there we go now that gives it a ph of five you see how that makes
first with the negative log then doing the math dot ceiling there
there we go all right so now with functions here
calc these are some of the things how could we write a function
you're going to define the function and calculating mortgage
i'll call it mort pay and now notice you would think that it when
indent automatically but for other things that i do or i might use
four spaces so i backspace i delete that and then i want to make
can i do i can define this function here so and and this is i'll
you can do more here so if i have the mortgage payment now we also
um table of contents i can jump right to mortgage payments so
and then i will define these in here
here so i'm going to just copy this and actually um
there we go so i'm going to show you one way to do this and then
okay there we go and more functions here so one of the things that
is just put everything in here
you probably don't need that extra line and same here so this
the payment maybe that's all you need you want to be able to then
print out the answer so that works another way is
what i'm going to do i'm going to copy this and i'm going to show
p r t and for this one i'm going to require input input p r t
and i'm going to return payment
so this one's nice if that's the if and you know there we go so
prompt you know this could this could go a lot of different places
maybe then just put this function in and return the payment like
it's going to go so two different situations and that's why you
that's why you know i'll make it you know p r t so we know what
is different so there we go so that's that's one one way
and i have here more functions now the interactive polynomial
with that too i'm going to do one more up here because i wanted to
enter a number to convert to scientific notation so if we have
convert so if i have a as my variable so there's my scientific
and if i take that and convert this i could create a function to
a there we go and maybe it just takes that input of a
there we go so we take this and move around um
um oh but i would probably have it as a string here so i could go
uh i could instead of printing it
and so we may you know i could just make that a string and then
so i probably don't need this a equals
and it should give you n times 10 to the x so just to give you
i want you to be able to you create the functions and then the
graph with sliders we we have that so turn that into a new turn
but here's the examples how you can just take and and that's the
to you know through this course you learn and you're practicing
parts that now you know and you can turn just the important parts
into their own functions and you can you know give them other
and there you go uh create a function for you know how long it
go back to that other one again turn that into a function and all
is going to be in a financial app that you'll make so what you can
all of these and you could have this work out that it's within all
have it within uh within google co-lab where you have text that
calculate mortgage payment number two retirement account balance
the text there and then require input which option do you want and
that's that's one way to do it defining all the functions having
the menu and then when you pick your option then it runs that
want to get to is that you're putting all this together and it
you can use this for other things you know calculating your own
with what you're doing certifications one and two see now where
the end of this and you have understand the math and you have all
you know calculate things graph things solve problems and then you
the next unit which i call it week 15 is going to be the wrapping
so we reached the home stretch in our algebra journey here and now
all the different things we've been doing with math we've been
taking things that turn into x lists of x y values that we can
at how we can get the get that data from the web from the cloud
and bring that data in whether it be columns in a table or all
in those x y coordinates and then we can do math to it so really
been working with all the math content and now pretty much
beyond this we're going to bring that math content and into the
into the code and do a lot more code how can i get this data turn
then do whatever graph i can do and you know analyze the data so
get to the code so now this is some ways you can bring in data
do other things so let's talk about the other sources pandas is
with data frames tables columns rows everything like that so we're
the matplot library we've done that before and we're also going to
going to import files and that's also going to give our file
io input output there we go i separate these out because you can
takes a few seconds i already did it so run it once and that saves
because we want to go through you'll see test some things now we
ways that we can get the files all right here's one option if you
you can upload it and because we imported that google dialogue or
this is all we need files dot upload and we're going to upload
file dialogue you can search for on your computer and that's what
that as that variable uploaded and then so i have my file name
take that uploaded file and iteration so iter and the argument is
the next one and what that is going to do is just one time you
going to select that and store it as file name and here that file
know that it's a csv so pandas has this nice building pd dot read
get to and don't worry about this it's because i already stored
for you know whatever file you upload so uploaded file name and it
it will store it as this table so there we go these three lines
you know give you the file dialogue upload it from your computer
when you select that file it's stored as table one awesome so
in in a minute here another way is you can get a csv from a url so
looking at different websites and you found you know this uh url
uh yeah this this guy uh seems to put put out a few good examples
dot csv old faithful geyser you know it rups for a little you know
regular basis that's why it's called old faithful and that just
can look at so i'll just store it as this variable url which is
the csv there you go plenty you could also and i didn't include
you wanted to you know make your own like you know input statement
somebody else using you know you made this program for somebody
to just copy and paste the url and store it you know that works
so you just put the url here store it as variable url now same
dot uh because we imported pan does it as pd pd dot read csv and i
and that's enough and i'll store it as table one
okay and yes those imports and everything that you run i just even
you so that's good for maybe 20 minutes google colab will uh have
on their server and you know colab has a runtime once we started
30 minutes of inactivity or even if you're active like you know
busy day i think it's like about 12 hours of running it'll time
well wait i haven't been inactive but there's still an absolute
start it again so that gives that gives you time you can import
to go through and then run a few of these and tinker with it okay
to repeat those steps and again you know importing you know
few seconds to run it and then prompting you know if we want to do
test some things you don't have to upload it every time that saves
so there we go now we have this what do we want to do with it you
we're going to eventually determine what columns we want and
remember numpy arrays that's what we're that's what we end up
i even still commented this out but you could display the whole
especially the the more you get into big data you know that's
resource consuming and so i i include that in there you know just
but what else might we want to do i might just want to print out
as table one for this example so i might just want to print out
one dot head and if i don't put a number in parentheses it will
put a number in there and it's going to give me the headings and i
that give me the headings in two rows that might be enough you
you've seen the column you might want to see the see it here or
to take a look at it i want to see the heading i want to see the
two rows give me an idea of what kind of data because if i start
know that i'm not going to be able to convert that to a numpy
store column names as a variable because if i have table one in
one dot columns there you go so now this column names is a list of
um and again i can i only need to do this once and now that i have
them all right instead of printing out the heading i could and i
new line column names and then i could loop through them so i'll
range length column names so column names i'm going to get the
then each time i'll print that number the space and then that
way to do it or another way i could actually just loop through
and just print that each time so let's see what that looks like
benefits here so notice this is the first one we did uh there you
print statement that head statement gave me these but this table
and notice their index starts at one so that's just something to
and eruption wait time so there we go and notice these quotes are
with within the name of the call you know that's something the
more you get into uh working with data and maybe other people you
everything i'll tell you this you really want column names without
without spaces but you know there's ways to deal with that we can
usually makes it easier for this stuff and for like some of the
an idea of what i have and here again you see the column names you
and the the other way we did it index eruption length eruption
these exact column names so you know i could now this is how i did
here and i can see them so table one and then in those square
of that column i want and then also that name in single quotes to
that to a numpy array and then eruption length in minutes so again
square brackets and remember that extra space and those quotes
i include them and convert that to a numpy array so now i have my
can plot there you know going through each of them you know it's
x is 3.6 y is 779 x is 1.8 y is 54 oh no actually i had it as
1.8 i can graph the eruption length or i can do it for eruption
to the index again x is 1 y is 79 x is 2 y is 54 so i just graphed
can go back and do that for the second one also if you wanted to
numpy arrays i can call that function x.min and this you know if
like the entire table this just might be a good way i'll just take
because it's just a little bit of a buffer on the edge and store
five a little bit of a buffer y min y max so this goes back to
with graphing set my x min x max and each of these now notice i
doing in other other units we were defining the points here but i
defined as num numpy arrays so when i graph i can plot i can plot
you know the x refers to that array y refers to that array and i
so i have these here as numpy arrays and i can do them as a
all right let's see what this looks like
now i had it as both and it looks like a huge mess but one of the
i don't want the line graph is probably not useful so i'll just go
out right now and run it again and we see it seems to cluster it's
that's kind of interesting what if i change my x my y value maybe
what if i change this so what i can do is my y minimum and these
want to do now we know how to use your math graphing skills to
to get all this data into this graph and this is now where we get
do i can look at this and say all right you know they're all less
well actually they're all greater than zero so i can just make my
going to comment out the rest of this and i can make my y maximum
the rest of that and when we see that we might see it seems like
reason it's really rare for it to be around three and remember
here we are graphing the eruption length time so it really seems
minutes or about four minutes yeah interesting so we can look at
things that we can do now let's look at another twist on this you
names so remember earlier we made column names this array so i can
names one and that's my x name and my y name i'll make these
the actual names of your columns doing that once might save you
then you can reuse that variable here just yeah i don't have to
time now i have my x variable is that column to numpy my y
doing before but again reusing that variable save you some typing
why in a minute and i just want to show you that that same scatter
dimensions are there but you see using that as the column name i
and again without having to rewrite so now we have index and
there we go then if i wanted to talk about the eruption time or
the things that we were doing i can just change this i still want
uh columns one was the eruption length i'll change that to that
names everything else stays the same and again going to different
giving the dimensions of the graph based on that because these
i'll still have the same index because they did match but instead
and five i will have you know wait wait time in minutes you know
almost 100 minutes so we see that now again let's get to some
it looks like maybe i have this range of 40 minutes to you know
like let's say this is in yellowstone let's say you go to visit
i have to wait it just erupted i want to go do other things when
i come back in 40 minutes should i come back in 90 minutes you
could keep you you know waiting there almost an hour but let's
patterns here again the default i keep this index i want to zoom
so i'll go to that index that x value i'll keep the same minimum
value instead of that plus five maybe i'll make it like 50 and
that's interesting i'm just going to run this again doesn't help
see now instead of a scatter plot actually i'll keep the scatter
but i'll also make it a line graph and i'll make the dots red and
and you see that just looks nice and if i don't you know there's
want that then i can just make my x x minimum you know one that
comment that that way i don't even get distracted by that there we
now besides seeing the scatter pot that was a mess the line graph
interesting things with very few exceptions if it was a shorter
the next one's a longer weight closer to 90 and then the next
weight longer weight you see every so often you get one that it
but we get a shorter weight a longer weight a shorter weight you
that happens most of the time so what we can do is we could look
oh well how long was it last time and then therefore i can use
that from you know we get that from looking at the graph here so
you could probably then now connecting this to you know real-time
doing this then we could graph you know a certain amount of this
table that always just updates you know when it erupted and how
each time you know just you know maybe even we could get this to
erupted it stopped erupting and then do the calculations what was
eruption time add that new data and we could be looking at this
to give people you know real-time estimates of it just erupted
eruption and get it down even probably to some like you know uh
that you know the point is that you would want to be able to say
minutes later or 90 minutes later i want to be able to have i
you know if it just erupted and it was an 80 minute wait then you
you know 50 minutes so you get some range that you know when to
don't have to wait too long and that's really what we want to get
these patterns and be able to then predict the next one you know
if i go to here and i want to be able to predict and say oh all
of 60 minutes so i'm going to just predict that the next wait time
and if we really want we can just change this to like 55
so with the wait time of 50 minutes then the next one wasn't quite
of well i wouldn't go i wouldn't wait more than 80 minutes i might
up so there we go because remember the other graph the eruption
minutes you are two you know two minutes and it could be two
five minutes that's not even that long so you don't want to be you
going to miss it all so yeah just interesting we can use this to
math of it we have we you know once you have those column names
so once we have we get that table what once you have that table
we have those column names and then we can do other things with
whatever we want you know number them you know just loop through
pick certain ones and i'll use that as my x and y so that's the
minimum maximum we can try this because we want to make this
and maybe certain things you can comment out and certain things
modify just a little bit that what you can use the same code for
whatever table you have this is a good start you start getting
to compare what am i trying to graph and then as you get into it
you can always then copy all this and then you know do in here
some text to give you know yourself or whoever read this some some
this code cell and you know that that's the beauty of the colab
like you can delete things and retry things or you can keep that
this is interesting information keep that and then just do a new
you know let's do the next next analysis so here's another way to
then graph it this particular library so not a csv but the full
of weather data so yes may install need to only install once right
i just have this as its own cell there you go pip install medial
doing that i mean this actually might take almost 30 seconds
so sometimes that seems like forever so i already did that and
um successfully installed and then we go on to the next one and
else working with this you put put in some text areas here so now
columns i have in this library so time uh and all the other these
average temperature minimum temp maximum temperature the amount of
amount of snow wind direction wind speed the pressure so average
uh air pressure uh the wind gusts so uh after wind speed we have
and the last one is uh time in the sun so you know how many
would you get and these are really good i picked these because it
you know you can things like wind speed you know plan your uh wind
time in the sun plan for your solar panels and where to put them
um so i have these to remind me and then the reminder change start
and you know point we're going to use this a lot so what arguments
latitude longitude meters above the ground so now we have these
up for yourself and you don't use it for a while and then you
variables you can use so all this you know we can just keep this
because we have from numpy we're going to import mean because
and then the rest of these are from you know the media stat
daytime plot and for media stat we're going to just import these
it's useful put the documentation in you know that here's the
you know put that in there as a comment again just like the other
people good to keep track of these things so now we know what
period and what i wanted to do is i just picked you know sometime
start and end so i have eight time there we go year month day your
so the person who put out this one example online did this for
commented that out and i did one for philadelphia and i picked a
city because it you know the uh if you want to click places and
he had a lot of decimal places so i just wanted to round it to two
you know you know in philadelphia in general and then round it to
where we got so it's a some random street corner in the city and
how many meters above the ground so i put 10 because this could be
on top of a building and i wanted to compare this to somewhere in
closely packed buildings does that affect wind speed well we're
the ground so this is in you know residential neighborhood that is
buildings but i picked a point in the suburbs and i picked a point
open field as something to compare so now i have these two points
uh so daily so that's the function in in media stat and there we
you know these are arguments that point and then start time and
daily data dot fetch and i'm going to store it as my data now we
my data and which one do i want i want wind speed for this one and
dot to numpy and i'm going to store that so now num data is my
that we want to do this library requires this function here i'll
that variable uh got fetched that's also from media stat i'll
a numpy array so i want to make that a number i want to take that
that column and make that a numpy array so i'll print that you
to get the mean to compare so now i have the second one again i'll
function fetch the data convert it to a numpy array and in this
but remember num data and num data too they're my two numpy arrays
so we can plot the line plot the line there we go and
and so i have this you know these two things i have you know the x
since i know that i made my since i know that i made my start and
30 days i wanted to make the x value there you go same thing one
it includes the first one so there we go and then i can plot these
all right now i'll tell you why i have that commented out i'll
these because this works like uh i wanted to again connect it with
matplot library that we use i wanted to connect it to that same
using and show you that that's what you can do you know get those
matplot.show but i commented this out this works also just a
you can just take that my data dot plot and then in parentheses
these two work so i just wanted to show you i'll leave them in
to connect this with the same type of math and plotting we're
so i had it calculate and then just display you know the city mean
rounded it but and quite honestly this is why we do data analysis
i really thought the average wind speed in this suburban area that
field would have been significantly higher and it was definitely
um maybe you know a little bit of a tunnel effect maybe there is
you know the buildings maybe that wasn't high enough also at least
and if it's high enough that's a little bit closer to the river
gives off a little bit more wind and this was a little bit closer
effect but there we go so then we see the mean but beyond that we
to day and you know they're still these two points that i picked
so it tracks they're in the same area the wind speeds go up and
patterns but we see that not just the mean but at every single
you know we could take a look now i made this so that's good and
we can pick like any number of days so i could since all the rest
just pick this and say well what about over the course of the year
one and maybe i make that 12 31 and there we go so if it would
and 365 so i want to graph it this way so from one to 365 and 365
up perfectly then i might have to do one more or one less but we
oh value error and it was 365 357 oh that's really interesting all
and so we can see you know the scattering but also i liked this
you know not 365 days that seemed like that would be it i'm not
right now maybe there were some days that were missing but you
pattern but you know maybe that sometimes that happens we go and
know take out missing information or incomplete information but
the day that i picked happened to be slightly lower than average
bit you know 14 miles an hour 8 miles an hour and then we can see
wind speed you know the average then what you could do is you know
that average you actually don't need to plot it out because it
averages you can work on that so if your wind speed is you know in
almost it's like 14 miles an hour throughout the year then you can
wind turbine and it would be actually relatively small but what
you need for 14 mile an hour winds and you can do some
how much electricity would that generate for you over the course
and again you can you know you can do that with you know any other
you know maybe you know you're trying to plan something you know
temperatures just one other thing i did just was you know
for you know a month just to show you and and all the rest of this
and what i did is i just made it a loop so you know range 1 to 11
month and i have you know what month there we go and you know
this because i thought oh well is that does that change and these
um yeah the way that the x value displays sometimes it seems like
but we can see we have you know wind speed and we can just see you
over the course of it and you see each month i have the mean and
and and then the graph so we can just see it's just interesting
for each month the display it a little this might be a little
interest or you could have something that displays them all in
four the grid it gets to be small graphs though but nonetheless we
when it goes down so i just wanted to show you some of these
with this with this graph and you know beyond that that there's
to in you know any other data you find if you you know you're
them maybe it's a csv but maybe somebody you know put together an
not only have the data and then that's stored somewhere but you
so that you have all these already how can i get a point and how
from any of those points so things that you can make and things
somebody else made you know different ways that you can find this
to give you some more tools now you know now that you know math
you know some more tools and some more sources of data
so what i want to show you here is just a few more things that you
and we already looked at over here on the left the table of
get to appear disappear then we have the search you can even
and then we have this folder icon where you can click to mount
and then once you do that then you can also see give it permission
it's mounting the google drive once you do that then you'll see it
so you can unmount the google drive if you want if if you wanted
so this makes it easy to find things and move things back and
then the really big thing down here is the look at these tags you
that are already in the google colab you see adding form from
get the code right here you can copy it or even click it you know
right in the place where you want to put it you click insert all
and notice this even uses javascript within python interfaces this
again all these and some of these you know downloading files
from google drive from github all kinds of things importing
you know that are in co-laboratory all of these zip reader there's
can do open files from github from your google drive from your
just upload those so it even gets down in here into pandas data
we want to get our math skills too that we can take data from
pandas part and then bring it in and then do some different math
display it in different ways and that's what we want to take this
you'll see below this video there's other code that i'll include
every one of these but check these out i mean there's so many
into colab that you can you can do you know open up a sample you
colab notebook i just call it code tester and i just have
and you know let's try this let's try that and then you know you
of stuff that works but here's all these things available and then
another colab notebook of just a few other things you know to
continue you know some things that you can do with math and with
upon this leading to you know working with data and doing some
so check these out and you know tinker with them and enjoy
wow you made it so now having gone through this now you should
you should be familiar with all the key concepts and how to write
algebra you should have your at least one or however you organized
ready with all of your scripts for solving all different sorts of
through certification one two and three and you have the ability
problems and you know write the code or reference code that you've
to solve these problems so there you go you should be you should
foundational math because it is the math that we're going to use
so many other things in math including data science data science
formulas like this functions like you've been working on you know
graphing so now you have an understanding of all that and then you
for yeah statistics data science and a few other subjects too so
step we will do a pre-calc trig that type of topic so you know
other graphs we didn't get to in in algebra because they're a
other sorts of patterns dealing with locations of things and
triangles so that'll be something that we'll do next and again
you with statistics and data science because as you represent data
of mathematical analyses to see relationships among data points
get you to be able to detect more and more complex relationships
foundation i feel like you have a good foundation hopefully you're
you made it and on to on to the next adventure
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.