December 2017
Intermediate to advanced
386 pages
10h 42m
English
We start by defining a function that plots a superposition of waves, with the following code:
xvalues = np.linspace(0, 40, 500)def plot_function(ratio=0.1): plt.figure(figsize=(10,3)) yvalues = np.cos(2*np.pi*xvalues) + \ np.cos(2*np.pi*ratio*xvalues) plt.plot(xvalues, yvalues, color='green', lw=2) plt.axis([0, 40, -2.1, 2.1]) plt.show()
Calling plot_function() by itself produces a static plot of a wave function. The ratio argument is used to specify the ratio between the frequencies of the superimposed waves.
To create an interactive display, simply execute the following in a Jupyter code cell:
from ipywidgets import interact interact(plot_function, ratio=(0.1, 1.1, 0.01))None
This will generate a display similar to the one ...
Read now
Unlock full access