Struct math_functions::F2D
source · pub struct F2D(_);Expand description
Representation of a function with 2 variables
Implementations§
source§impl F2D
impl F2D
sourcepub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
pub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
Builds a F2D from a string and a context (meaning that you can use already created functions)
use math_functions::{F1D,F2D,F3D, context::Context};
use std::str::FromStr;
let func = F1D::from_str("x^2").unwrap();
let mut ctx = Context::new();
ctx.add_f1d("POWER", &func);
let func2 = F2D::build("y(POWER+POWER)", &ctx).unwrap();
assert_eq!(func2, F2D::from_str("y(x^2+x^2)").unwrap());sourcepub fn eval(&self, x: f64, y: f64) -> f64
pub fn eval(&self, x: f64, y: f64) -> f64
Evaluate F2D at a given (x,y)
use math_functions::{F2D,approx};
use std::str::FromStr;
let func = F2D::from_str("ysin(x)").unwrap();
assert_eq!(approx(func.eval(2., 0.5), 5), 0.45465);sourcepub fn derivative(&self) -> Vec2<Self>
pub fn derivative(&self) -> Vec2<Self>
Computes the derivative of a F2D
use math_functions::{F2D, Vec2};
use std::str::FromStr;
let func = F2D::from_str("yln(x)").unwrap();
assert_eq!(func.derivative(), Vec2{ x: F2D::from_str("y/x").unwrap(), y:
F2D::from_str("ln(x)").unwrap()});