{ "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 }