Skip to main content

derivative_stencil

Function derivative_stencil 

Source
pub fn derivative_stencil<T>(
    f: &T,
    x: f64,
    step_size: Option<f64>,
    order: DerivativeStencilOrder,
) -> Result<Vec<f64>, ErrorsJSL>
where T: Fn(f64) -> f64,
Expand description

A derivative of f at x from the five-point stencil f(x − 2h), …, f(x + 2h). Returns a one-element vector holding the requested derivative.

step_size is relative, as for derivative_2_point. The default balances truncation against rounding for each formula: ε^{1/5} for the first and third derivatives and ε^{1/6} for the second and fourth (around 10⁻³), since higher derivatives divide rounding errors by higher powers of h.