from __future__ import print_function from math import exp N = 60 x0 = 5 x1 = 9.0/2 xpp = x0 xp = x1 f = lambda n: 4 + (1.0/2)**n for n in range(2, N): x = -1.0 + 2*xp - (3/4.0)*xpp print('n: %4d, sim: %23.23f, formula: %23.23f, error: %10e' % (n, x, f(n), abs(x-f(n)))) xpp = xp xp = x