Computational Modelling Blog

Blogging with the IPython Notebook Example

This is the first line of the notebook

In [1]:
print("Hello World")
Hello World

Some equation $f(x) = \exp(-\alpha x) \cos(x)$.

In [5]:
from numpy import exp, cos

def f(x, alpha=0.1):
    """The equation implemented in a Python function"""
    return exp(- alpha * x) * cos(x)

Now create a plot of the function:

In [6]:
%matplotlib inline
import pylab as p
In [16]:
xs = p.linspace(0, 40, 200)
p.plot(xs, f(xs, 0.1), label ='f(x, 0.1)')
p.plot(xs, f(xs, 0.2), '--', label ='f(x, 0.2)')
p.xlabel('x')
p.legend()
Out[16]:

The last line of the notebook.

Comments