import math def df(f,x,h): return (f(x+h)-f(x) )/h def df1(f,x,h): return (f(x)-f(x-h) )/h def df2(f,x,h): return (f(x+h) - f(x-h))/(2.*h) x=0.7 for h in [1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,\ 1e-14,1e-15,1e-16,1e-17,1e-18]: print h, df(math.cos,x,h)+math.sin(x),df1(math.cos,x,h)+math.sin(x),df2(math.cos,x,h)+math.sin(x)