Introduction notebook¶
This page gives a similar introduction as intro.rst, but written as a jupyter
notebook.
exampy
is an example Python package that contains some very basic math functions. As an example, we can compute the square of a number as
[1]:
import exampy
exampy.square(3.)
[1]:
9.0
Similarly, we can compute the cube of a number:
[2]:
exampy.cube(3.)
[2]:
27.0
A general method for raising a number to a given power is given by the Pow class. For example, to get the fourth power of 3, do:
[3]:
po= exampy.Pow(p=4.)
po(3.)
[3]:
81.0
exampy
also includes a simple method for integrating a function, in the exampy.integrate
submodule. This submodule contains the function riemann
that approximates the integral of any one-parameter function as a Riemann sum. riemann
takes as input (i) the function to integrate, (ii) the integration range’s lower limit and (iii) the upper limit, and (iv) optionally, the number of intervals to divide the integration range in. For example, the integrate the square function of the
range [0,1], do:
[4]:
from exampy import integrate
integrate.riemann(exampy.square,0,1)
[4]:
0.35185185185185186
If we increase the number of intervals from the default (which is 10), we get a better approximation to the correct result (which is 1/3):
[5]:
integrate.riemann(exampy.square,0,1,n=1000)
[5]:
0.33350016683350014