{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Thanks to unicode, we may use Greek letters directly in our code. \n", "\n", "In this Jupyter Notebook, lets use θ (theta), π (pi) and τ (tau) with τ = 2 * π. \n", "\n", "Then we'll plot the graph of Euler's Formula, e to the i θ over the range 0 to τ.\n", "\n", "In Python we signify i, the root of -1, as 1j for readability, so lets bind i to 1j as well." ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.00000\n" ] } ], "source": [ "from math import e, pi as π\n", "τ = 2 * π\n", "i = 1j\n", "result = e ** (i * τ)\n", "print (\"{:1.5f}\".format(result.real))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below we import some industrial grade tools used for plotting with Python. The same greek letter names remain active and guide the construction of a domain t and range s. Then we label the graph and generate a picture. plt.show(), if used, produces a plot in its own window." ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "t = np.arange(0.0, τ, 0.01)\n", "s = np.array([(np.e ** (i * θ)).real for θ in t])\n", "plt.plot(t, s)\n", "plt.xlabel('radians')\n", "plt.ylabel('real part')\n", "plt.title('Euler\\'s Formula from 0 to tau')\n", "plt.grid(True)\n", "plt.savefig(\"euler_test.png\") # uploaded to Flickr for display below" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![euler_test.png](https://c2.staticflickr.com/2/1562/26157050065_392d24fb62_z.jpg \"euler_test.png\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 1 }