ruut-functions

Crates.ioruut-functions
lib.rsruut-functions
version0.2.1
sourcesrc
created_at2023-02-16 10:22:46.788113
updated_at2024-07-18 08:58:26.310996
descriptionA crate to parse math functions from string (1D,2D,3D,ND) and perform symbolic derivation, gradient, hessian
homepage
repository
max_upload_size
id786632
size78,106
Ludovico Furlanetto (NotLudovico)

documentation

README

Features

  • 1D, 2D, 3D, ND (with custom variables) functions
  • Set params and assign values (default is 0.0)
  • Compute derivatives of any orders, gradients, hessian
  • F1D can be numerically integrated
  • Supports the following functions:
    • Ln, Sin, Cos, Tan, Sec, Csc, ASin, ACos, ATan, Sinh, Cosh, Tanh, Coth, Sech, Csch, ASinh, ACosh, ATanh, Abs
  • Some kind of expression semplification

Examples

use ruut_functions::{f3d, F3D};

fn main() {
    let mut f = f3d!("x^3+y^2+yx^2+[eta]");
    f.set_par("eta", 6.9);
    assert_eq!(f.eval(0., 0., 0.), 6.9);
    assert_eq!(
        f.gradient(),
        vec![f3d!("2xy+3x^2"), f3d!("2y+x^2"), f3d!("0")]
    );
    assert_eq!(
        f.hessian(),
        vec![
            vec![f3d!("2y+6x"), f3d!("2x"), f3d!("0")],
            vec![f3d!("2x"), f3d!("2"), f3d!("0")],
            vec![f3d!("0"), f3d!("0"), f3d!("0")]
        ]
    )


    let f = f1d!("abs(x)+sin(x)");
    assert_eq!(f.eval(-2),2.90929742683)
}
Commit count: 0

cargo fmt