Function num_dual::partial_hessian
source · pub fn partial_hessian<G, T: DualNum<F>, F: DualNumFloat, M: Dim, N: Dim>(
g: G,
x: OVector<T, M>,
y: OVector<T, N>
) -> (T, OVector<T, M>, OVector<T, N>, OMatrix<T, M, N>)where
G: FnOnce(OVector<HyperDualVec<T, F, M, N>, M>, OVector<HyperDualVec<T, F, M, N>, N>) -> HyperDualVec<T, F, M, N>,
DefaultAllocator: Allocator<T, N> + Allocator<T, M> + Allocator<T, M, N> + Allocator<T, U1, N> + Allocator<HyperDualVec<T, F, M, N>, M> + Allocator<HyperDualVec<T, F, M, N>, N>,Expand description
Calculate second partial derivatives with respect to vectors.
let x = SVector::from([4.0, 3.0]);
let y = SVector::from([5.0]);
let fun = |x: SVector<HyperDualSVec64<2, 1>, 2>, y: SVector<HyperDualSVec64<2, 1>, 1>|
y[0] / (x[0].powi(2) + x[1].powi(2)).sqrt();
let (f, dfdx, dfdy, d2fdxdy) = partial_hessian(fun, x, y);
assert_eq!(f, 1.0);
assert_relative_eq!(dfdx[0], -0.16);
assert_relative_eq!(dfdx[1], -0.12);
assert_relative_eq!(dfdy[0], 0.2);
assert_relative_eq!(d2fdxdy[0], -0.032);
assert_relative_eq!(d2fdxdy[1], -0.024);