# stapgrootte.py - de fout van een voorwaartse en een centrale differentie
import math

f = math.exp            # testfunctie f(x) = e^x: haar afgeleide is e^x zelf
x = 1.0
exact = math.exp(x)

print("  h       voorwaarts  centraal")
for k in range(1, 14):
    h = 10.0 ** -k
    voorw = (f(x + h) - f(x)) / h
    centr = (f(x + h) - f(x - h)) / (2 * h)
    print("1e-%02d   %9.1e   %9.1e" % (k, abs(voorw - exact), abs(centr - exact)))
