Struct math_functions::F1D
source · pub struct F1D(_);Expand description
Representation of a function with 1 variable
Implementations§
source§impl F1D
impl F1D
sourcepub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
pub fn build(input: &str, ctx: &Context<'_>) -> Result<Self, ParsingError>
Builds a F1D from a string and a context (meaning that you can use already created functions)
use math_functions::{F1D, 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 = F1D::build("POWER(x)+POWER(x)", &ctx);
assert_eq!(func2, F1D::from_str("x^2+x^2"));sourcepub fn eval(&self, x: f64) -> f64
pub fn eval(&self, x: f64) -> f64
Evaluate F1D at a given x
use math_functions::{F1D,approx};
use std::str::FromStr;
let func = F1D::from_str("xsin(x)").unwrap();
assert_eq!(approx(func.eval(2.), 5), 1.81859);sourcepub fn derivative(&self) -> Self
pub fn derivative(&self) -> Self
Computes the derivative of a F1D
use math_functions::F1D;
use std::str::FromStr;
let func = F1D::from_str("xln(x)").unwrap();
assert_eq!(func.derivative(), F1D::from_str("ln(x)+1").unwrap());