Skip to main content

diff_central

Function diff_central 

Source
pub fn diff_central(xs: &[f64], ys: &[f64]) -> Result<Vec<f64>, String>
Expand description

Central difference approximation of the derivative.

Given paired arrays xs (abscissae) and ys (ordinates) of length n >= 3, returns n-2 derivative estimates at the interior points xs[1..n-1]:

dy/dx[i] ≈ (ys[i+1] - ys[i-1]) / (xs[i+1] - xs[i-1])

This is a second-order accurate approximation.