pub fn hessian<G, T: DualNum<F>, F: DualNumFloat, D: Dim>(
g: G,
x: OVector<T, D>
) -> (T, OVector<T, D>, OMatrix<T, D, D>)where
G: FnOnce(OVector<Dual2Vec<T, F, D>, D>) -> Dual2Vec<T, F, D>,
DefaultAllocator: Allocator<T, D> + Allocator<T, U1, D> + Allocator<T, D, D> + Allocator<Dual2Vec<T, F, D>, D>,Expand description
Calculate the Hessian of a scalar function.
let v = SVector::from([4.0, 3.0]);
let fun = |v: SVector<Dual2SVec64<2>, 2>| (v[0].powi(2) + v[1].powi(2)).sqrt();
let (f, g, h) = hessian(fun, v);
assert_eq!(f, 5.0);
assert_relative_eq!(g[0], 0.8);
assert_relative_eq!(g[1], 0.6);
assert_relative_eq!(h[(0,0)], 0.072);
assert_relative_eq!(h[(0,1)], -0.096);
assert_relative_eq!(h[(1,0)], -0.096);
assert_relative_eq!(h[(1,1)], 0.128);