{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Complex contour of a pendulum\n\ncomplex surface of a Hamiltoanian \n\n\\begin{align}H(q, p) = \\frac{p^2}{2} + k \\cos q\\end{align}\n\nwith $Re[E]=const.$\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nnp.seterr(invalid='ignore')\n\n\ntwopi = 2*np.pi\nx = np.linspace(-twopi,twopi,100)\ny = np.linspace(-2,2,100)\n\nx,y = np.meshgrid(x,y)\neps = 0.5\nHam = lambda q,p: p**2/2 + eps*np.cos(q)\n\n#fig, ax = plt.subplots(1,1,projection=\"3d\")\nfig = plt.figure()\nfig.patch.set_visible(0)\nax = fig.add_subplot(1,1,1,projection=\"3d\")\nax.patch.set_alpha(0)\n\nax.contour(x,y,Ham(x,y),10,zdir='z',offset=0,colors=\"k\")\nE=0\ndef P(q,E):\n return np.sqrt(2*(E-eps*np.cos(q)))\n\ntwopi = 2*np.pi\nq = np.linspace(-twopi,twopi,2000) + 0.j\np = P(q,E)\nax.plot(q.real, p.real, p.imag, \"-r\",lw=3)\nax.plot(q.real, -p.real, p.imag, \"-r\",lw=3)\n\nsample=100\nE=0 + np.linspace(0,1,sample)*1.j\nq = np.linspace(-twopi,twopi,sample) + 0.j\nq,E=np.meshgrid(q,E)\np = P(q,E)\nax.plot_wireframe(q.real,p.real,p.imag,alpha=0.2)\nax.plot_wireframe(q.real,-p.real,p.imag,alpha=0.2)\nax.set_zlim(0,1.5)\nax.set_xlim(-twopi,twopi)\nax.set_ylim(-2,2)\nax.set_xlabel(\"$\\mathrm{Re}(q)$\",fontsize=18)\nax.set_ylabel(\"$\\mathrm{Re}(p)$\",fontsize=18)\nax.set_zlabel(\"$\\mathrm{Im}(p)$\",fontsize=18)\nax.set_xticks([-twopi, -np.pi, 0,np.pi, twopi])\nE=0\nq0=np.arccos(2*E/eps)\n#ax.text(q0,0,0,r\"$a$\", fontsize=15,bbox=dict(facecolor='w', edgecolor='none', pad=0,alpha=1))\n#ax.text(-q0,0,0,r\"$-a$\",fontsize=15,bbox=dict(facecolor='w', edgecolor='none', pad=0,alpha=0.8))\nax.set_yticks([-2,0,2])\nax.set_zticks([0,1])\nax.set_xticklabels([r\"$-2\\pi$\", r\"$-\\pi$\", r\"$0$\", r\"$\\pi$\", r\"$2\\pi$\"])\n#plt.tight_layout()\n#plt.savefig(\"complex_pen.svg\")\nplt.show()" ] } ], "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.9.7" } }, "nbformat": 4, "nbformat_minor": 0 }