hi in this video we'll go over how we
can build mathematical models with Tracy
the turtle so just as a review we've
learned how to draw graphs with Tracy
using four loops
every time X updates a new value of y is
calculated and then we move Tracy to the
new XY position using the set position
command Tracy leaves a trail when moving
to a new location and that gives us a
graph now let's talk about modeling with
Tracy first let's go over some
vocabulary a mathematical model is a
description of a phenomenon process or
problem using mathematical equations we
build mathematical models to help us
understand the world around us and
predict future events on the left you
can see a population model that might
help an ecologist understand why an
animal population is growing or
shrinking on the right we have a weather
model that predicts how a typhoon will
progress both of these models were built
by developing mathematical equations to
describe real world relationships today
we'll be developing our own real
mathematical models with Tracy we can
use Tracy to build models of real world
situations we already know how to graph
with Tracy so instead of graphing x and
y we can graph any two variable
relationship so we could graph interest
earned over time
ice cream singles over temperature or
the energy production of a wind farm
over wind speed let's take a look so
here's a scenario Paula has $600 she
invests her money in an account that has
a 4% annual interest rate that is
compounded continuously how will her
savings grow over 60 years let's use
Tracy to help Paula understand her
savings to build our model we'll need to
write an equation that describes the
relationship between time and the amount
of money that Paula has in her account
because this is a compound interest
problem it helps us to remember that the
general equation for compound interest
is a equals P times e raised to the RT
power
in this equation a represents the amount
of money in the account at a given time
period of money she initially invests in
the account he is a famous irrational
number sometimes called Euler's number
after the swiss mathematician it's
approximately 2.718 but because it's
irrational the decimal will continue
infinitely without repeating our
represents the interest rate for the
account and T represents the amount of
time that has passed in years let's use
this formula to write our model okay so
let's look at the information that we
have we know that our initial investment
or principal is $600 so let's set our
principal equal to 600 we also know that
interest rate is 4% so we can go ahead
and set the rate equal to point zero
four be careful to make sure that you
write the interest rate as a decimal and
not as a percentage now instead of
plotting X&Y we want to plot time and
savings since we'll be calculating
savings based on the time that has
passed we'll write a for loop where we
update time we want to calculate savings
over 60 years
so we'll say for time and range 60 and
now in the for loop we can just write
our equation now we need to write our
equations so that Python can understand
it in Python when we want to use the
number e we need to write math II
remember Python is very picky about
typos and capitalization Python also has
a special way of writing exponents we'll
want to type two asterisks to show that
we want to raise math to the power of
rate times time
we'll need parentheses to show that we
want the product of rate in time as the
exponent
let's go code this so just like before
our world is already set up so that our
axes are labeled now I'll set my values
for principal and rate and I want to
define these outside of my function
because it makes it easier for me to
change these values if I need to later
and I'll actually want to be careful
because I noticed that my y axis is
labeled savings in hundreds of dollars
so instead of 600 I want my principal to
actually just be six because that's how
many hundreds of dollars I'm looking at
now I'll write my for loop so for time
in range sixty and then I'm going to
type my equation
and remember I used math da e instead of
E and I used two asterisks because I
wanted to raise ^ and if you need any
reminders you have it in your left hand
Docs alright let's try running this code
okay can you see why nothing happened
we're calculating the amount in our for
loop but we're not telling Tracy to move
after the amount is calculated so I want
to say set position time okay all right
that's a lot better now because I've
used variables to set my principal and
rate it's easy to see how my model
changes if the interest rate is only 3%
or if the initial amount is $800 here's
a model that plots the temperature of a
region over the course of a year you can
see how the temperature is low in
January goes up to its hottest around
the middle of the year and then falls
again towards the end of the year now
it's your turn to create some
mathematical models