Trait exmex::Differentiate[][src]

pub trait Differentiate<T: Clone> where
    Self: Sized + Express<T> + Display + Debug
{ fn to_deepex<'a>(
        &'a self,
        ops: &[Operator<'a, T>]
    ) -> ExResult<DeepEx<'a, T>>
    where
        Self: Sized,
        T: DataType + Float,
        <T as FromStr>::Err: Debug
;
fn from_deepex(
        deepex: DeepEx<'_, T>,
        ops: &[Operator<'_, T>]
    ) -> ExResult<Self>
    where
        Self: Sized,
        T: DataType + Float,
        <T as FromStr>::Err: Debug
; fn partial(&self, var_idx: usize) -> ExResult<Self>
    where
        T: DataType + Float,
        <T as FromStr>::Err: Debug
, { ... } }
Expand description

feature = "partial" - Trait for partial differentiation.

Required methods

feature = "partial" - Every trait implementation needs to implement the conversion to a deep expression to be able to use the default implementation of partial.

feature = "partial" - Every trait implementation needs to implement the conversion from a deep expression to be able to use the default implementation of partial.

Provided methods

feature = "partial" - This method computes a new expression that is the partial derivative of self with default operators.

Example
use exmex::prelude::*;

let mut expr = FlatEx::<f64>::from_str("sin(1+y^2)*x")?;
let dexpr_dx = expr.partial(0)?;
let dexpr_dy = expr.partial(1)?;

assert!((dexpr_dx.eval(&[9e5, 2.0])? - (5.0 as f64).sin()).abs() < 1e-12);
//             |    
//           The partial derivative dexpr_dx does depend on x. Still, it
//           expects the same number of parameters as the corresponding
//           antiderivative. Hence, you can pass any number for x.  

assert!((dexpr_dy.eval(&[2.5, 2.0])? - 10.0 * (5.0 as f64).cos()).abs() < 1e-12);
Arguments
  • var_idx - variable with respect to which the partial derivative is computed
Errors
  • If you use custom operators this might not work as expected. It could return an ExError if an operator is not found or compute a wrong result if an operator is defined in an un-expected way.

Implementors