我试图使用Scipi. Misc的导函数找到泰勒级数的系数,但我在Scypy库中不断得到错误。
我的代码:
d_pts = order*2
if d_pts % 2 == 0: # must be odd and greater than derivative order
d_pts += 1
coefficients = []
for i in range(1, order+1):
coefficients.append(round((derivative(function, center, n=i, order=d_pts))/math.factorial(i), 5))
return coefficients
错误消息:
<ipython-input-31-c44b369ecec2> in findCoefficients(function, order, center)
5 coefficients = []
6 for i in range(1, order+1):
----> 7 coefficients.append(round((derivative(function, center, n=i, order=d_pts))/math.factorial(i), 5))
8 return coefficients
/usr/local/lib/python3.8/dist-packages/scipy/misc/common.py in derivative(func, x0, dx, n, args, order)
142 ho = order >> 1
143 for k in range(order):
--> 144 val += weights[k]*func(x0+(k-ho)*dx,*args)
145 return val / prod((dx,)*n,axis=0)
146
TypeError: 'float' object is not callable
有人知道怎么修吗?
1条答案
按热度按时间9fkzdhlc1#
看起来您传递的不是函数而是浮点值。请确保
function
不是浮点值而是函数。另外,请注意,不建议使用导数函数。https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html