{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
Dr. Joshua Vaughan
\n",
"joshua.vaughan@louisiana.edu
\n",
"http://www.ucs.louisiana.edu/~jev9637/
\n",
"\t
\n",
" Figure 1: A Mass-Spring-Damper System \n",
"
\n", "\t\n", " Figure 2: The Interactive Mass-Spring-Damper Response \n", "
\n", "Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(FloatSlider(value=1.0, description='f', max=1.8, min=0.2, step=0.01), FloatSlider(value=0.05, description='z', max=0.9, step=0.01), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# import the IPython widgets\n", "from ipywidgets import interact\n", "import ipywidgets as widgets\n", "\n", "# Set up the function that plots the repsonse based on slider changes\n", "def plot_response(f = 1.0, z = 0.05):\n", " # Make the figure pretty, then plot the results\n", " # \"pretty\" parameters selected based on pdf output, not screen output\n", " # Many of these setting could also be made default by the .matplotlibrc file\n", " fig = plt.figure(figsize=(9, 6))\n", " ax = plt.gca()\n", " plt.subplots_adjust(bottom=0.17, left=0.17, top=0.96, right=0.96)\n", " plt.setp(ax.get_ymajorticklabels(), family='serif', fontsize=18)\n", " plt.setp(ax.get_xmajorticklabels(), family='serif', fontsize=18)\n", " ax.spines['right'].set_color('none')\n", " ax.spines['top'].set_color('none')\n", " ax.xaxis.set_ticks_position('bottom')\n", " ax.yaxis.set_ticks_position('left')\n", " ax.grid(True, linestyle=':', color='0.75')\n", " ax.set_axisbelow(True)\n", " \n", " wn = 2 * np.pi * f\n", " wd = wn * np.sqrt(1 - z**2)\n", " \n", " # Define x(t)\n", " x = np.exp(-z * wn * t) * (x0[0] * np.cos(wd*t) + (z * wn * x0[0] + x0[1])/wd * np.sin(wd*t))\n", " \n", " plt.plot(t, x, linewidth=2)\n", " plt.xlabel('Time (s)',family='serif', fontsize=22, weight='bold', labelpad=5)\n", " plt.ylabel('Position (m)',family='serif', fontsize=22, weight='bold', labelpad=10)\n", " plt.ylim(-1.1, 1.1)\n", " plt.xlim(0, 5)\n", " \n", "\n", "# Call the slider interaction\n", "# f is changes in frequency, allowing between 0.2 and 1.8Hz at 0.1Hz increments\n", "# z is damping ratio, allowing between 0 and 0.9 and 0.05 increments\n", "interact(plot_response, f=(0.2, 1.8, 0.01), z = (0, 0.9, 0.01));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "