pchip.RdPiecewise Cubic Hermitean Interpolation Polynomials.
pchip(xi, yi, x)
pchipfun(xi, yi)pchip is a `shape-preserving' piecewise cubic Hermite polynomial
approach that apptempts to determine slopes such that function values do
not overshoot data values.
pchipfun is a wrapper around pchip and returns a function.
Both pchip and the function returned by pchipfun are vectorized.
xi and yi must be vectors of the same length greater or equal 3
(for cubic interpolation to be possible), and xi must be sorted.
pchip can be applied to points outside [min(xi), max(xi)], but
the result does not make much sense outside this interval.
Values of interpolated data at points x.
Moler, C. (2004). Numerical Computing with Matlab. Revised Reprint, SIAM.
x <- c(1, 2, 3, 4, 5, 6)
y <- c(16, 18, 21, 17, 15, 12)
pchip(x, y, seq(1, 6, by = 0.5))
#> [1] 16.00000 16.88750 18.00000 19.80000 21.00000 19.33333 17.00000 15.96667
#> [9] 15.00000 13.63750 12.00000
fp <- pchipfun(x, y)
fp(seq(1, 6, by = 0.5))
#> [1] 16.00000 16.88750 18.00000 19.80000 21.00000 19.33333 17.00000 15.96667
#> [9] 15.00000 13.63750 12.00000
if (FALSE) { # \dontrun{
plot(x, y, col="red", xlim=c(0,7), ylim=c(10,22),
main = "Spline and 'pchip' Interpolation")
grid()
xs <- seq(1, 6, len=51)
ys <- interp1(x, y, xs, "spline")
lines(xs, ys, col="cyan")
yp <- pchip(x, y, xs)
lines(xs, yp, col = "magenta")} # }