scipy.misc.central_diff_weights¶
- scipy.misc.central_diff_weights(Np, ndiv=1)[源代码]¶
返回NP点中心导数的权重。
假定等间距的功能点。
If weights are in the vector w, then derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)
- 参数
- Np集成
中心导数的点数。
- ndiv整型,可选
分区数。默认值为1。
- 退货
- wndarray
NP点中心导数的权重。它的大小是 Np 。
注意事项
对于大量的点可能是不准确的。
参考文献
示例
我们可以计算函数的导数值。
>>> from scipy.misc import central_diff_weights >>> def f(x): ... return 2 * x**2 + 3 >>> x = 3.0 # derivative point >>> h = 0.1 # differential step >>> Np = 3 # point number for central derivative >>> weights = central_diff_weights(Np) # weights for first derivative >>> vals = [f(x + (i - Np/2) * h) for i in range(Np)] >>> sum(w * v for (w, v) in zip(weights, vals))/h 11.79999999999998
该值接近解析解:f‘(X)=4x,因此f’(3)=12