Copyright (C) 2010-2020 Luke Olson
Copyright (C) 2020 Andreas Kloeckner
import numpy as np
import matplotlib.pyplot as pt
What this demo does is sum the series $$ \exp(x) \approx \sum_{i=0}^n \frac{x^i}{i!}, $$ for varying $n$, and varying $x$. It then prints the partial sum, the true value, and the final term of the series.
a = 0.0
x = 1e0 # flip sign
true_f = np.exp(x)
e = []
for i in range(0, 10): # crank up
d = np.prod(
np.arange(1, i+1).astype(np.float))
# series for exp
a += x**i / d
print(a, np.exp(x), x**i / d)
e.append(abs(true_f-a)/true_f)
pt.semilogy(e)