This notebook is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
You will need to have the following packages installed in order to run this notebook:
ipython
ipywidgets
matplotlib
numpy
pandas
The interactive dashboard will run fine in regular Jupyter notebook mode, launch it by running,
jupyter notebook
To get this to work in Jupyter Lab, you need to first run the following on the command line,
jupyter labextension install @jupyter-widgets/jupyterlab-manager
After successfully installing the @jupyter-widgets/jupyterlab-manager
JupyterLab extension, launch JupyterLab:
jupyter lab
%matplotlib inline
from IPython.display import clear_output, display
from ipywidgets import interact, interactive, fixed, FloatSlider, FloatText, RadioButtons
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import undamped_oscillator
def sim_plot(
sim_time,
delta_t,
method,
):
simulation_df = undamped_oscillator.simulation(
sim_time=sim_time,
delta_t=delta_t,
method=method,
)
figwidth = 5 # inches
figheight = 0.618 * figwidth # golden ratio
figsize = (figwidth, 1.5 * figheight)
fig, ax = plt.subplots(nrows=2, ncols=1, figsize=figsize, dpi=120, sharex=True);
ax[0].plot(simulation_df["time"], simulation_df["length"], "-")
ax[1].plot(simulation_df["time"], simulation_df["velocity"], "-")
ax[0].set_xlabel("time (s)")
ax[0].set_ylabel("length (m)")
ax[1].set_xlabel("time (s)")
ax[1].set_ylabel("velocity (m/s)");
integration_methods = ["forward", "midpoint", "leapfrog"]
sim_time = FloatSlider(
description="sim_time",
value=5.0,
min=1,
max=10,
step=1,
)
delta_t = FloatText(
description="delta_t",
value=0.01,
)
method = RadioButtons(
options=integration_methods,
description="integration method",
)
interactive_window = interactive(
sim_plot,
sim_time=sim_time,
delta_t=delta_t,
method=method,
)
display(interactive_window)
interactive(children=(FloatSlider(value=5.0, description='sim_time', max=10.0, min=1.0, step=1.0), FloatText(v…