Function peroxide::numerical::utils::jacobian

source ·
pub fn jacobian<F: Fn(&Vec<AD>) -> Vec<AD>>(f: F, x: &Vec<f64>) -> Matrix
Expand description

Jacobian Matrix

§Description

: Exact jacobian matrix using Automatic Differenitation

§Type

(F, &Vec<f64>) -> Matrix where F: Fn(&Vec<AD>) -> Vec<AD>

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let x = c!(1, 1);
    let j = jacobian(f, &x);
    j.print();

    //      c[0] c[1]
    // r[0]    1   -1
    // r[1]    1    2
}

fn f(xs: &Vec<AD>) -> Vec<AD> {
    let x = xs[0];
    let y = xs[1];

    vec![
       x - y,
       x + 2.*y,
   ]
}