{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gaussian Plots" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = [1,2,3,4,5]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data2 = [2*x for x in data]\n", "data2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you may have guessed, x acts as a variable that takes on each value in the list data. The first part of the command computes 2*x for each x and assigns the resulting value to the same location in data2 that x was drawn from in data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import math\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gaussian(N,s):\n", " return math.sqrt(2/(math.pi*N))*math.exp(-2*s**2/N)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gaussian(10,0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ins=np.linspace(-10,10,100)\n", "data10=[gaussian(10,s) for s in ins]\n", "data20=[gaussian(20,s) for s in ins]\n", "data100=[gaussian(100,s) for s in ins]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(ins,data10)\n", "plt.ylabel('P(N,s)')\n", "plt.xlabel('s (imbalance)')\n", "plt.title('Gaussian with N=10')\n", "plt.savefig('Gauss10.png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(ins,data20)\n", "plt.ylabel('P(N,s)')\n", "plt.xlabel('s (imbalance)')\n", "plt.title('Gaussian with N=20')\n", "plt.axis([-10,10,0,0.25])\n", "plt.savefig('Gauss20.png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(ins,data100)\n", "plt.ylabel('P(N,s)')\n", "plt.xlabel('s (imbalance)')\n", "plt.title('Gaussian with N=100')\n", "plt.axis([-10,10,0,0.25])\n", "plt.savefig('Gauss100.png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }