bundles / scipy 1.17.1 / scipy / stats / _finite_differences / _central_diff_weights
function
scipy.stats._finite_differences:_central_diff_weights
Signature
def _central_diff_weights ( Np , ndiv = 1 ) Summary
Return weights for an Np-point central derivative.
Extended Summary
Assumes equally-spaced function points.
If weights are in the vector w, then derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)
Parameters
Np: intNumber of points for the central derivative.
ndiv: int, optionalNumber of divisions. Default is 1.
Returns
w: ndarrayWeights for an Np-point central derivative. Its size is
Np.
Notes
Can be inaccurate for a large number of points.
Examples
We can calculate a derivative value of a function.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
✗Aliases
-
scipy.stats._finite_differences._central_diff_weights