Skip to contents

Mirrors the C# Linear, CubicSpline, and Polynomial interpolaters of the Numerics library. x_transform, y_transform, and extrapolate are Linear-only in C# (neither CubicSpline nor Polynomial has a transform surface or an Extrapolate() method), so they must be left at their defaults for method = "cubic_spline" or "polynomial".

Usage

interpolate(
  x,
  y,
  xout,
  method = c("linear", "cubic_spline", "polynomial"),
  order = NULL,
  x_transform = c("none", "logarithmic", "log", "normal_z"),
  y_transform = c("none", "logarithmic", "log", "normal_z"),
  sort_order = c("ascending", "descending"),
  extrapolate = FALSE
)

Arguments

x, y

numeric vectors of equal length defining the knots.

xout

numeric vector of positions to interpolate at.

method

"linear" (the default), "cubic_spline", or "polynomial".

order

the polynomial order – there are order + 1 terms for each polynomial function. Required when method = "polynomial"; must be NULL otherwise.

x_transform, y_transform

one of "none" (the default), "logarithmic" (also accepted as "log" – both spellings are equivalent, see the note below), or "normal_z". Linear-only.

sort_order

"ascending" (the default) or "descending", describing x.

extrapolate

whether to extend the end segments beyond the knots. Default FALSE, which clamps to the end knot, matching the C# Interpolate() default; TRUE calls the C# Extrapolate() method instead. Linear-only.

Value

a numeric vector the same length as xout.

Note

x_transform/y_transform accept both "log" and "logarithmic" for the same Transform::Logarithmic value everywhere a transform argument appears in this package (curve_interpolate(), tabular_function(), and here); "logarithmic" (matching the C# enum member name Transform.Logarithmic) is the spelling used in this package's own examples and documentation.

Examples

interpolate(c(1, 2, 3, 4), c(10, 20, 30, 40), c(1.5, 2.5))
#> [1] 15 25
interpolate(c(1, 2, 3, 4), c(10, 20, 30, 40), c(1.5, 2.5), method = "cubic_spline")
#> [1] 15 25
interpolate(c(1, 2, 3, 4), c(10, 20, 30, 40), c(1.5, 2.5), method = "polynomial", order = 3)
#> [1] 15 25