In [ ]:
%matplotlib inline
from numpy import exp, cos, linspace
import pylab
from ipywidgets import interact
Want to understand $f(t) = \exp(-\alpha t) \cos(\omega t)$
In [ ]:
def f(t, alpha, omega):
"""Computes and returns exp(-alpha*t) * cos(omega*t)"""
return exp(-alpha * t) * cos(omega * t)
We can execute the function for valuel of $\alpha$ and $\omega$:
In [ ]:
f(t=0.1, alpha=1, omega=10)
Although sometimes a plot is more instructive:
In [ ]:
def plot_f(alpha, omega):
ts = linspace(0, 5, 400) # many points in the interval [0, 5]
ys = f(ts, alpha, omega)
pylab.plot(ts, ys, '-')
In [ ]:
plot_f(alpha=0.1, omega=12)
A wide range of convenience tools, for example graphical interaction elements called Widgets:
In [ ]:
interact(plot_f, alpha=(0, 2, 0.1), omega=(0, 20, 0.5))