Function interp::interp_slice [−][src]
pub fn interp_slice<T>(x: &[T], y: &[T], xp: &[T]) -> Vec<T> where
T: Num + PartialOrd + Copy,
Expand description
Linearly interpolate the data points given by the x
and y
slices at each of the points in
the xp
slice.
Returns the equivalent y coordinates to each of the x coordinates given by xp
.
This is equivalent to running interp
iteratively for each value in xp
, but more efficient
as intermediate calculations are not repeated.
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 for each xp
. If the length of either
is 1, y[0]
is returned. If both are 2 elements or longer the interpolations are performed as
expected.
Example
use interp::interp_slice; let x = vec![0.0, 1.0, 2.0, 3.0]; let y = vec![1.0, 3.0, 4.0, 2.0]; let xp = vec![0.5, 2.5, 4.0]; assert_eq!(interp_slice(&x, &y, &xp), vec![2.0, 3.0, 0.0]);