Automatic differentiation toolbox for Peroxide
Modify your Cargo.toml
as follows.
toml
[dependencies]
peroxide = "0.30"
#[ad_function]
macro generates {}_grad
, {}_hess
from Fn(f64) -> f64
automatically.
{}_grad
: gradient of function {}
{}_hess
: hessian of function {}
```rust
extern crate peroxide; use peroxide::fuga::*;
fn main() { f(2f64).print(); // x^3 = 8 fgrad(2f64).print(); // 3 * x^2 = 12 fhess(2f64).print(); // 6 * x = 12 }
fn f(x: f64) -> f64 { x.powi(3) // x^3 } ```