Skip to content

Commit

Permalink
update class 12 pre-work
Browse files Browse the repository at this point in the history
  • Loading branch information
justmarkham committed Sep 15, 2015
1 parent 7cbb74b commit 48f4f1b
Show file tree
Hide file tree
Showing 2 changed files with 376 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Tuesday | Thursday

**Homework:**
* Watch Rahul Patwari's videos on [probability](https://www.youtube.com/watch?v=o4QmoNfW3bI) (5 minutes) and [odds](https://www.youtube.com/watch?v=GxbXQjX7fC0) (8 minutes) if you're not comfortable with either of those terms.
* Read these excellent articles from BetterExplained: [An Intuitive Guide To Exponential Functions & e](http://betterexplained.com/articles/an-intuitive-guide-to-exponential-functions-e/) and [Demystifying the Natural Logarithm (ln)](http://betterexplained.com/articles/demystifying-the-natural-logarithm-ln/).
* Read these excellent articles from BetterExplained: [An Intuitive Guide To Exponential Functions & e](http://betterexplained.com/articles/an-intuitive-guide-to-exponential-functions-e/) and [Demystifying the Natural Logarithm (ln)](http://betterexplained.com/articles/demystifying-the-natural-logarithm-ln/). Then, review this [brief summary](http://nbviewer.ipython.org/github/justmarkham/DAT8/blob/master/notebooks/12_e_log_examples.ipynb) of exponential functions and logarithms.

<!--
Expand Down
375 changes: 375 additions & 0 deletions notebooks/12_e_log_examples.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,375 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exponential functions and logarithms"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import math\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exponential functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is **e**? It is simply a number (known as Euler's number):"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.718281828459045"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.e"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**e** is a significant number, because it is the base rate of growth shared by all continually growing processes.\n",
"\n",
"For example, if I have **10 dollars**, and it grows 100% in 1 year (compounding continuously), I end up with **10\\*e^1 dollars**:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"27.18281828459045"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 100% growth for 1 year\n",
"10 * np.exp(1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"73.890560989306508"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 100% growth for 2 years\n",
"10 * np.exp(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Side note: When e is raised to a power, it is known as **the exponential function**. Technically, any number can be the base, and it would still be known as **an exponential function** (such as 2^5). But in our context, the base of the exponential function is assumed to be e.\n",
"\n",
"Anyway, what if I only have 20% growth instead of 100% growth?"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"12.214027581601698"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 20% growth for 1 year\n",
"10 * np.exp(0.20)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"14.918246976412703"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 20% growth for 2 years\n",
"10 * np.exp(0.20 * 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Logarithms"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the **(natural) logarithm**? It gives you the time needed to reach a certain level of growth. For example, if I want growth by a factor of 2.718, it will take me 1 unit of time (assuming a 100% growth rate):"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.99989631572895199"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# time needed to grow 1 unit to 2.718 units\n",
"np.log(2.718)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If I want growth by a factor of 7.389, it will take me 2 units of time:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1.9999924078065106"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# time needed to grow 1 unit to 7.389 units\n",
"np.log(7.389)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If I want growth by a factor of 1, it will take me 0 units of time:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# time needed to grow 1 unit to 1 unit\n",
"np.log(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If I want growth by a factor of 0.5, it will take me -0.693 units of time (which is like looking back in time):"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"-0.69314718055994529"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# time needed to grow 1 unit to 0.5 units\n",
"np.log(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connecting the concepts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, the exponential function and the natural logarithm are **inverses** of one another:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"5.0"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.log(np.exp(5))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4.9999999999999991"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.exp(np.log(5))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 48f4f1b

Please sign in to comment.