{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Helmholtz Equation for Vibrating Membrane

\n", "

\n", "A visualization is made of the solution of the Helmholtz equation for a vibrating\n", " membrane:\n", " \n", " $u(x,y,t) = cos(c sqrt(5)*t)*sin(2x)* cos(y)$.\n", " \n", " Based on example in: \n", "http://matplotlib.org/examples/mplot3d/wire3d_animation_demo.html" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "# MembraneHelmholz.ipynb\n", "\n", "%matplotlib notebook\n", "from mpl_toolkits.mplot3d import axes3d \n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import matplotlib.animation as animation\n", "import matplotlib\n", "\n", "t = 0 # initial time\n", "den = 390.0 #density kg/m2\n", "ten = 180.0 # tension N/m2\n", "c = np.sqrt(ten/den) # propagation velocity\n", "s5 = np.sqrt(5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true, "scrolled": false }, "outputs": [], "source": [ "def membrane(t,X,Y): # analytic solution vibrating membrane\n", " return np.cos(c * s5* t) * np.sin( 2* X)*np.sin(Y)\n", "\n", "fig = plt.figure()\n", "ax = fig.add_subplot(111, projection = '3d')\n", "xs = np.linspace(0, np.pi,32) # 0 to pi increm: pi/32\n", "ys = np.linspace(0, np.pi,32) \n", "ax.set_zlim(-1, 1) # z limits\n", "X, Y = np.meshgrid(xs,ys) \n", "Z = membrane(0, X, Y) # initial condition \n", "wframe = None\n", "ax.set_xlabel('X') \n", "ax.set_ylabel('Y')\n", "ax.set_title('Vibrating membrane')\n", "\n", "def update(idx): # called by animation\n", " t = tt[idx]\n", " global wframe\n", " if wframe:\n", " ax.collections.remove(wframe) # remove last frame\n", " Z = membrane(t,X,Y) # membrane at t != 0\n", " wframe = ax.plot_wireframe(X,Y,Z) \n", " \n", "tt = range(200) # interval = delay between iterations\n", "ani = animation.FuncAnimation(fig, update,frames = 100,interval = 300)" ] } ], "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.13" } }, "nbformat": 4, "nbformat_minor": 2 }