import numpy as np import matplotlib.pyplot as pt def f(x): return np.exp(x) - 2 xgrid = np.linspace(-2, 3, 1000) pt.grid() pt.plot(xgrid, f(xgrid)) xtrue = np.log(2) print(xtrue) print(f(xtrue)) errors = [] x = 2 xbefore = 3 slope = (f(x)-f(xbefore))/(x-xbefore) xbefore = x x = x - f(x)/slope print(x) errors.append(abs(x-xtrue)) print(errors[-1]) for err in errors: print(err) # Does not quite double the number of digits each round--unclear. for i in range(len(errors)-1): print(errors[i+1]/errors[i]**1.618)