[−][src]Function bacon_sci::interp::spline_free
pub fn spline_free<N: ComplexField>(
xs: &[N::RealField],
ys: &[N],
tol: N::RealField
) -> Result<CubicSpline<N>, String>
Create a free cubic spline interpolating the given points.
Given a set of ordered points, produce a piecewise function of cubic polynomials that interpolate the points given the second derivative of the piecewise function at the end points is zero and the piecewise function is smooth.
Params
xs
x points. Must be real because cubic splines keep track of ranges within
which it interpolates. Must be sorted.
ys
y points. Can be complex. ys[i] must match with xs[i].
tol
the tolerance of the polynomials
Examples
use bacon_sci::interp::spline_free; fn example() { let xs: Vec<_> = (0..=10).map(|x| x as f64).collect(); let ys: Vec<_> = xs.iter().map(|x| x.exp()).collect(); let spline = spline_free(&xs, &ys, 1e-8).unwrap(); for i in 0..1000 { let i = i as f64 * 0.001; assert!((spline.evaluate(i).unwrap() - i.exp()).abs() / i.exp() < 0.25); } }