Demo of Python in Jupyter Notebook

SymPy: Open Source Symbolic Mathematics

This section uses the SymPy package to perform symbolic manipulations, and combined with numpy and matplotlib, also displays numerical visualizations of symbolically constructed expressions.

We first load sympy printing extensions, as well as all of sympy:

Elementary operations

Algebra

Calculus

Illustrating Taylor series

We will define a function to compute the Taylor series expansions of a symbolically defined expression at various orders and visualize all the approximations together with the original function

With this function defined, we can now use it for any sympy function or expression

This shows easily how a Taylor series is useless beyond its convergence radius, illustrated by a simple function that has singularities on the real axis:

Basic Numerical Integration: the Trapezoid Rule

A simple illustration of the trapezoid rule for definite integration:

$$ \int_{a}^{b} f(x)\, dx \approx \frac{1}{2} \sum_{k=1}^{N} \left( x_{k} - x_{k-1} \right) \left( f(x_{k}) + f(x_{k-1}) \right). $$


First, we define a simple function and sample it between 0 and 10 at 200 points

Choose a region to integrate over and take only a few points in that region

Plot both the function and the area below it in the trapezoid approximation

Compute the integral both at high accuracy and with the trapezoid approximation