pub fn interp<T>(x: &[T], y: &[T], xp: T) -> T
Expand description
Linearly interpolate the data points given by the x
and y
slices at point xp
.
Returns the equivalent y coordinate to the x coordinate given by xp
.
If the lengths of x
and y
differ, only the number of elements in the shorter slice are
considered; excess elements are ignored.
If the length of either x
or y
is 0, 0 is returned. If the length of either is 1, y[0]
is
returned. If both are 2 elements or longer the interpolation is performed as expected.
Example
use interp::interp;
let x = vec![0.0, 1.0, 2.0, 3.0];
let y = vec![1.0, 3.0, 4.0, 2.0];
assert_eq!(interp(&x, &y, 1.5), 3.5);