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());Trait Implementations§
impl StructuralPartialEq for F1D
Auto Trait Implementations§
impl RefUnwindSafe for F1D
impl Send for F1D
impl Sync for F1D
impl Unpin for F1D
impl UnwindSafe for F1D
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