template<int Derivative, typename Scalar, int Size>
class Eigen::Stencil< Derivative, Scalar, Size >
Finite-difference weights on an arbitrarily spaced grid.
Computes the weights of the order-Derivative finite-difference formula for the grid points, using Fornberg's recursive algorithm:
B. Fornberg, "Generation of Finite Difference Formulas on Arbitrarily Spaced Grids", Math. Comp. 51 (1988), 699-706.
The implementation follows the equivalent, in-place algorithmic form given in the follow-up:
B. Fornberg, "Calculation of Weights in Finite Difference Formulas", SIAM Review 40 (1998), 685-691.
The evaluation point is fixed at 0: points are read as offsets from wherever the derivative is to be evaluated. This is lossless, since shifting every point (and the evaluation point) by the same amount leaves the weights unchanged, so a caller evaluating at x shifts points by -x first. Derivative == 0 is supported and corresponds to interpolation: the weights reproduce f(0) exactly for every polynomial of degree less than Size.
points are used in exactly the order given: this class does not sort or otherwise reorder them. Fornberg's paper notes that the order nodes are introduced in affects the conditioning of the recursion (not the exact result, by uniqueness of the interpolating polynomial), and suggests introducing nodes in order of ascending distance from the evaluation point for stability. Choosing and applying such an ordering, including e.g. a Leja ordering for complex nodes, is the caller's responsibility.
For offsets h * k at a fixed relative layout k and varying step h, the weights scale as w_i(h * k) == h^(-Derivative) * w_i(k): computing weights once on k and scaling by h^(-Derivative) avoids repeating the O(Size^2 * Derivative) recursion for every step. Stencil only produces the weights for the points it is given; choosing or adapting h itself is the caller's responsibility.
- Template Parameters
-
| Derivative | The order of the derivative the weights approximate. |
| Scalar | The scalar type of the grid points and weights. Must be a non-integer type. |
| Size | The number of grid points. |