Estimate the Taylor polynomial of f at x by polynomial fitting.
f : callable
x : scalar
degree : int
scale : scalar
order : int or None
p : poly1d instance
The appropriate choice of “scale” is a trade-off; too large and the function differs from its Taylor polynomial too much to get a good answer, too small and round-off errors overwhelm the higher-order terms. The algorithm used becomes numerically unstable around order 30 even under ideal circumstances.
Choosing order somewhat larger than degree may improve the higher-order terms.