0
class Diff:
def __init__(self, f, h):
self.f = f
self.h = h
class Backward1(Diff):
def __call__(self, x):
f = self.f
h = self.h
return (f(x)-f(x-h))/h
from math import sin, pi
A = Backward1(sin,1E-5)
print A(pi)
想要計算幾個h值,如[h = 2 **( - k)for k in range(10)]。如何做到這一點的任何提示?謝謝!如何使用for-loop作爲函數中的參數