[−][src]Function bacon_sci::interp::spline_clamped
pub fn spline_clamped<N: ComplexField>(
xs: &[N::RealField],
ys: &[N],
(f_0, f_n): (N, N),
tol: N::RealField
) -> Result<CubicSpline<N>, String>
Create a clamped 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 first derivative of the piecewise function at the end points is the same as the given values 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].
(f_0, f_n)
The derivative values at the end points.
tol
the tolerance of the polynomials
Examples
use bacon_sci::interp::spline_clamped; 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_clamped(&xs, &ys, (1.0, (10.0f64).exp()), 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); } }