{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Square Well" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from matplotlib.animation import PillowWriter\n", "import animatplot as amp\n", "\n", "\n", "def psi(x, t):\n", " return (\n", " 2**-0.5 * np.exp(t * 1j) * np.sin(np.pi * x)\n", " + 0.5 * np.exp(t * 4j) * np.sin(2 * np.pi * x)\n", " + 0.5 * np.exp(t * 9j) * np.sin(3 * np.pi * x)\n", " )\n", "\n", "\n", "x = np.linspace(0, 1, 20)\n", "t = np.linspace(0, 10, 20)\n", "\n", "X, T = np.meshgrid(x, t)\n", "Y1 = psi(X, T).real\n", "Y2 = psi(X, T).imag\n", "\n", "timeline = amp.Timeline(t, \"s\", 24)\n", "\n", "ax = plt.axes(xlim=[0, 1], ylim=[-2, 2])\n", "block1 = amp.blocks.Line(X, Y1, ax=ax)\n", "block2 = amp.blocks.Line(X, Y2, ax=ax)\n", "\n", "anim = amp.Animation([block1, block2], timeline)\n", "\n", "# Your standard matplotlib stuff\n", "plt.title(\n", " r\"Particle in a Box: $|\\Psi\\rangle = \\frac{1}{\\sqrt{2}}\"\n", " r\"|E_1\\rangle + \\frac{1}{2}|E_2\\rangle + \\frac{1}{2}|E_3\\rangle$\",\n", " y=1.03,\n", ")\n", "plt.xlabel(\"position\")\n", "plt.ylabel(r\"$\\Psi$\")\n", "plt.legend([\"Real\", \"Imaginary\"])\n", "\n", "anim.toggle()\n", "anim.timeline_slider()\n", "\n", "anim.save(\"sq_well.gif\", writer=PillowWriter(fps=5))\n", "plt.show()" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. image:: sq_well.gif" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "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 }