Skip to main content

derivative

Function derivative 

Source
pub fn derivative<F>(f: F, x: f64, h: f64) -> f64
where F: Fn(f64) -> f64,
Expand description

Numerical derivative using finite differences

§Arguments

  • f - Function to differentiate
  • x - Point at which to evaluate derivative
  • h - Step size (default: 1.0)

§Example

use dodecet_encoder::calculus;

let f = |x: f64| x * x;
let deriv = calculus::derivative(f, 2.0, 0.01);
assert!((deriv - 4.0).abs() < 0.1); // d/dx(x²) = 2x, at x=2, = 4