Skip to main content

simpson

Function simpson 

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

Composite Simpson’s 1/3 rule for numerical integration.

Given arrays xs (abscissae) and ys (ordinates) of equal length n >= 3, where n-1 (number of subintervals) must be even, computes:

sum_{i=0,2,4,…} (xs[i+2] - xs[i]) / 6 * (ys[i] + 4*ys[i+1] + ys[i+2])

Uses Kahan summation for the accumulation.