Interpolate equidistantly between End Points
Arguments
- y1
numeric vector of y-values at the beginning
- y2
numeric vector of y-values at the end. Must be as long as
y1- n
number of interpolation points including first and last value
- version
version of implementation
Value
matrix M with n columns and as many rows as there are
values in y1 (and also in y1). The first column contains the
values from y1, the last column contains the values from y2
and the n - 2 columns in between contain the interpolated values.
Examples
y1 <- c(1, 1, 1)
y2 <- c(0.1, 0.5, 0.8)
n <- 10
y <- interpolate_between(y1, y2, n)
barplot(y, beside = TRUE)
# Compare the performance of slightly different implementations
microbenchmark::microbenchmark(
v1 = interpolate_between(y1, y2, n, version = 1),
v2 = interpolate_between(y1, y2, n, version = 2),
v3 = interpolate_between(y1, y2, n, version = 3),
times = 1000,
check = function(x) kwb.utils::allAreIdentical(x[2:3]) &&
all(kwb.utils::almostEqual(x[[1]], x[[2]]))
)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> v1 20.3 20.9 21.7101 21.2 21.7 72.0 1000
#> v2 9.2 9.6 10.1614 9.8 10.2 84.2 1000
#> v3 8.7 9.2 9.6715 9.4 9.7 90.0 1000