def approximate_taylor_polynomial(f, x, degree, scale, order=None):
 if (order is None):
  order = degree
 n = (order + 1)
 xs = ((scale * np.cos(np.linspace(0, np.pi, n, endpoint=(n % 1)))) + x)
 P = KroghInterpolator(xs, f(xs))
 d = P.derivatives(x, der=(degree + 1))
 return np.poly1d((d / factorial(np.arange((degree + 1))))[::(-1)])

def approximate_taylor_polynomial ( f , x , degree , scale , order = None ) : if ( order is None ) : order = degree n = ( order + 1 ) xs = ( ( scale * np . cos ( np . linspace ( 0 , np . pi , n , endpoint = ( n % 1 ) ) ) ) + x ) P = KroghInterpolator ( xs , f ( xs ) ) d = P . derivatives ( x , der = ( degree + 1 ) ) return np . poly1d ( ( d / factorial ( np . arange ( ( degree + 1 ) ) ) ) [ : : ( - 1 ) ] )
estimate the taylor polynomial of f at x by polynomial fitting .