Type Definition num_dual::Dual2

source ·
pub type Dual2<T, F> = Dual2Vec<T, F, 1>;

Implementations§

Create a new scalar second order dual number from its fields.

Derive a scalar second order dual number

let x = Dual2::from_re(5.0).derive().powi(2);
assert_eq!(x.re, 25.0);            // x²
assert_eq!(x.v1[0], 10.0);         // 2x
assert_eq!(x.v2[(0,0)], 2.0);      // 2

The argument can also be a dual number

let x = Dual2::from_re(Dual64::from_re(5.0).derive())
    .derive()
    .powi(2);
assert_eq!(x.re.re(), 25.0);      // x²
assert_eq!(x.re.eps[0], 10.0);    // 2x
assert_eq!(x.v1[0].re, 10.0);     // 2x
assert_eq!(x.v1[0].eps[0], 2.0);  // 2
assert_eq!(x.v2[(0,0)].re, 2.0);  // 2