Skip to main content

gradient_2_point

Function gradient_2_point 

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

The gradient ∇f(x) of a scalar function of several variables by central differences, one coordinate at a time (2n evaluations).

step_size is relative: coordinate i is perturbed by h · max(|xᵢ|, 1), with default h = ε^{1/3} (about ten correct digits for well-scaled functions).