Crates.io | hyperdual |
lib.rs | hyperdual |
version | 1.3.0 |
source | src |
created_at | 2019-07-16 06:09:27.907982 |
updated_at | 2024-07-07 15:48:20.657413 |
description | Fully-featured Dual Number implementation with features for automatic differentiation of multivariate vectorial functions |
homepage | |
repository | https://github.com/christopherrabotin/hyperdual |
max_upload_size | |
id | 149346 |
size | 39,870 |
Fully-featured Dual Number implementation with features for automatic differentiation of multivariate vectorial functions into gradients.
extern crate hyperdual;
use hyperdual::{Dual, Hyperdual, Float, differentiate};
fn main() {
// find partial derivative at x=4.0
let univariate = differentiate(4.0f64, |x| x.sqrt() + Dual::from_real(1.0));
assert!((univariate - 0.4500).abs() < 1e-16, "wrong derivative");
// find the partial derivatives of a multivariate function
let x: Hyperdual<f64, 3> = Hyperdual::from_slice(&[4.0, 1.0, 0.0]);
let y: Hyperdual<f64, 3> = Hyperdual::from_slice(&[5.0, 0.0, 1.0]);
let multivariate = x * x + (x * y).sin() + y.powi(3);
assert!((res[0] - 141.91294525072763).abs() < 1e-13, "f(4, 5) incorrect");
assert!((res[1] - 10.04041030906696).abs() < 1e-13, "df/dx(4, 5) incorrect");
assert!((res[2] - 76.63232824725357).abs() < 1e-13, "df/dy(4, 5) incorrect");
}