[][src]Function autodiff::forward_autodiff::grad

pub fn grad<G>(f: G, x0: &[f64]) -> Vec<f64> where
    G: Fn(&[F]) -> F

Evaluates the gradient of f at x0

Examples

    // Define a multivariate function `f(x,y) = x*y^2`
    let f = |x: &[F]| x[0] * x[1] * x[1];

    // Differentiate `f` at `(1,2)`.
    let g = grad(f, &vec![1.0, 2.0]);
    println!("({}, {})", g[0], g[1]); // prints `(4, 4)`