The following is part of a on-going collection of Jupyter notebooks. The goal being to have a library of notebooks as an introduction to Mathematics and technology. These were all created by Gavin Waters. If you use these notebooks, be nice and throw up a credit somewhere on your page.

def

Alot of times when programing it is good to call something and pass varaible to that thing. An example in mathematics is defining a mathematical function $f(x)$

The syntax for setting up, creating, your definition is simple.

def name(variable):

do stuff
do more stuff
__return something else__

You can also use composition of functions for this

lets do something silly with this to illustrate the power.

The above code was simply $\sum_{n=1}^{10}\frac{1}{n}$. If you try this for very large numbers then it would be nice to not print all of the numbers and just the last one

We know that this series, the harmonic series, is divergent. One of the proofs collects the terms in groups, so that they always add up to a half. Could we write a script to give the number of terms for each half? Lets do the first 7 "halfs"

definitions as functions

To illustrate the function in a graphical way, we will use a package called numpy and matplotlib. See Numpy and Matplotlib post to see more about these.

The above code loads the packages, the below code sets up a grid of numbers that we can feed into f(x). That will give us our y values and then we can plot x-y graph.