scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
central_diff_weights(Np, ndiv=1)

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)

Notes

Can be inaccurate for a large number of points.

Parameters

Np : int

Number of points for the central derivative.

ndiv : int, optional

Number of divisions. Default is 1.

Returns

w : ndarray

Weights for an Np-point central derivative. Its size is :None:None:`Np`.

Return weights for an Np-point central derivative.

Examples

We can calculate a derivative value of a function.

>>> 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

This value is close to the analytical solution: f'(x) = 4x, so f'(3) = 12

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.misc._common.central_diff_weights

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/misc/_common.py#12
type: <class 'function'>
Commit: