%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;}
# keep output cells from shifting to autoscroll: little scrolling
# subwindows within the notebook are an annoyance...
Listen to Richard Feynman:
To make calculations, the Maya had invented a
system of bars and dots to represent numbers…
rules… to calculate and predict… the risings
and settings of Venus…. Only a few Maya priests
could do such elaborate calculations….
Suppose we were to ask one of them how to do
just one step in the process of predicting when
Venus will next rise as a morning star—subtracting
two numbers….. How would the priest explain?….
He could either teach us the… bars and dots and
the rule… or he could tell us what he was really doing:
Suppose we want to subtract 236 from 584.
First, count out 584 beans and put them in
a pot. Then take out 236 beans and put them
to one side. Finally, count the beans left
in the pot. That number is the result…
You might say, ‘My Quetzalcoatl! What
tedium… what a job!’
To which the priest would reply:
That’s why we have the rules…. The rules
are tricky, but they are a much more efficient
way of getting the answer…. We can predict
the appearance of Venus by counting beans
(which is slow, but easy to understand) or
by using the tricky rules (which is much
faster, but you must spend years in school to
learn them)…
Muḥammad ibn Mūsā al-Khwārizmī (c. 780-850):
Restoration and Balancing
by the Kalif Al-Mamun
around ninth century Baghdad?
Isaac Newton (1642-1727):
of potential calculations all at once…
$ \frac{dy}{dt} = g(y - a) $
then explodes * and keeps on exploding...
# make sure graphs are displayed in main notebook
%matplotlib inline
import numpy as np # make sure libraries are
import pandas as pd # in the namespace
import matplotlib as mpl
import matplotlib.pyplot as plt
from IPython.display import Image
plt.style.use('seaborn-whitegrid') # graphics setup
figure_size = plt.rcParams["figure.figsize"]
figure_size[0] = 10
figure_size[1] = 7
plt.rcParams["figure.figsize"] = figure_size
a = 10 # set the initial asymptote
g = 0.01 # set the growth rate
array = np.zeros((1001,2)) # initialize an array
exponential_function_df = pd.DataFrame(array,
columns=["time","value"]) # create a dataframe
# calculate values for the exponential function
for t in range(-500,501, 1):
exponential_function_df.time[t+500] = t
exponential_function_df.value[t+500] = a + np.exp(g*t)
exponential_function_df = exponential_function_df.set_index("time")
exponential_function_df.plot() # and graph
plt.ylabel("Value", fontsize=20) # set labels
plt.xlabel("Time", fontsize=20)
plt.suptitle("Exponential Growth", fontsize=28)
plt.title("asymptote = 10; growth rate = 0.01", fontsize=16)
<matplotlib.text.Text at 0x1160fb0b8>
Math presentation can be ugly inline:
Or prettier:
(1) $ \frac{dy}{dt} = d(y - a) $
(2) $ y = 10 + e^{0.01(t-10} $
Rule of 72 for Exponential Growth:
array = np.zeros((21,2)) # initialize an array
rule_of_72_df = pd.DataFrame(array,
columns=["rate","doubling_time_times_rate"]) # create a dataframe
rule_of_72_df.rate[0] = 0
rule_of_72_df.doubling_time_times_rate[0] = np.log(2)*100
for i in range(1, 21):
rule_of_72_df.rate[i] = i*.01
rule_of_72_df.doubling_time_times_rate[i] = (i *
np.log(2)/np.log(1 + i*.01))
rule_of_72_df = rule_of_72_df.set_index("rate")
rule_of_72_df.plot()
plt.ylabel("Doubling Time Times Rate", fontsize=20) # set labels
plt.xlabel("Rate", fontsize=20)
plt.xlim(0,)
plt.suptitle("Rule of 72", fontsize=28)
<matplotlib.text.Text at 0x109b70748>
For compounded growth rates of between 6.5% and 9.5% per period,
the product of the doubling time and the growth rate is closer
to 72 than to any other integer...
"exp" "E"
and Euler did it for us…
(dy/dt) = g(k - y)
k = 10 # set the final asymptote
g = 0.01 # set the growth rate
array = np.zeros((1001,2)) # initialize an array
exponential_function_df = pd.DataFrame(array,
columns=["time","value"]) # create a dataframe
# calculate values for the exponential function
for t in range(0, 1001, 1):
exponential_function_df.time[t] = t
exponential_function_df.value[t] = k + (0 - k) * np.exp(-g*t)
exponential_function_df = exponential_function_df.set_index("time")
exponential_function_df.plot() # and graph
plt.ylabel("Value", fontsize=20) # set labels
plt.xlabel("Time", fontsize=20)
plt.suptitle("Exponential Convergence", fontsize=28)
plt.title("asymptote = 10; growth rate = 0.01", fontsize=16)
<matplotlib.text.Text at 0x116a09780>
(3) $ \frac{dy}{dt} = g(y-a)\left(1-\frac{y}{k}\right) $
array = np.zeros((1001,2)) # initialize an array
logistic_df = pd.DataFrame(array,
columns=["time","value"]) # create a dataframe
a = 100
g = 0.03
k = 1000
logistic_df.time[0] = 0
logistic_df.value[0] = a + 0.1
for t in range(1,1001):
logistic_df.time[t] = t
logistic_df.value[t] = (logistic_df.value[t-1] + g *
(logistic_df.value[t-1]-a)*(1-logistic_df.value[t-1]/k))
logistic_df = logistic_df.set_index("time")
logistic_df.plot()
plt.ylabel("Value", fontsize=20) # set labels
plt.xlabel("Time", fontsize=20)
plt.suptitle("Logistic Curve", fontsize=28)
<matplotlib.text.Text at 0x1160e6748>