Struct math_functions::F3D
source · pub struct F3D(_);Expand description
Representation of a function with 3 variables
Implementations§
source§impl F3D
impl F3D
sourcepub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
pub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
Builds a F3D from a string and a context (meaning that you can use already created functions)
use math_functions::{F2D,F3D, context::Context};
use std::str::FromStr;
let func = F2D::from_str("yx^2").unwrap();
let mut ctx = Context::new();
ctx.add_f2d("CUSTOM", &func);
let func2 = F3D::build("z(CUSTOM+CUSTOM)", &ctx).unwrap();
assert_eq!(func2, F3D::from_str("z(yx^2+yx^2)").unwrap());sourcepub fn eval(&self, x: f64, y: f64, z: f64) -> f64
pub fn eval(&self, x: f64, y: f64, z: f64) -> f64
Evaluate F3D at a given (x,y,z)
use math_functions::{F3D,approx};
use std::str::FromStr;
let func = F3D::from_str("ysin(x)ln(z)").unwrap();
assert_eq!(approx(func.eval(2., 0.5, 4.), 5), 0.63028);sourcepub fn derivative(&self) -> Vec3<Self>
pub fn derivative(&self) -> Vec3<Self>
Computes the gradient of a F3D
use math_functions::{F3D, Vec3};
use std::str::FromStr;
let func = F3D::from_str("xyz^2").unwrap();
assert_eq!(func.derivative(), Vec3{ x: F3D::from_str("yz^2").unwrap(), y:
F3D::from_str("xz^2").unwrap(), z: F3D::from_str("2xyz").unwrap()});sourcepub fn hessian(&self) -> Matrix<F3D>
pub fn hessian(&self) -> Matrix<F3D>
Computes hessian matrix of the given function
use math_functions::{F3D, Matrix};
use std::str::FromStr;
let func = F3D::from_str("3x^2+y^4+xyz^2").unwrap();
let hessian = func.hessian();
println!("{}", hessian);
//| 6 | z^2 | 2yz |
//| z^2 | 12y^2 | 2xz |
//| 2yz | 2xz | 2xy |
let result: Matrix<F3D> = Matrix::new(
vec![
F3D::from_str("6").unwrap(),
F3D::from_str("z^2").unwrap(),
F3D::from_str("2yz").unwrap(),
F3D::from_str("z^2").unwrap(),
F3D::from_str("12y^2").unwrap(),
F3D::from_str("2xz").unwrap(),
F3D::from_str("2yz").unwrap(),
F3D::from_str("2xz").unwrap(),
F3D::from_str("2xy").unwrap(),
],
3,
3,
);
assert_eq!(result, hessian);Trait Implementations§
impl StructuralPartialEq for F3D
Auto Trait Implementations§
impl RefUnwindSafe for F3D
impl Send for F3D
impl Sync for F3D
impl Unpin for F3D
impl UnwindSafe for F3D
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more