InterpBarycentric: ND barycentric interpolation at points Xi for a function with...

Description Usage Arguments Value Author(s) References Examples

View source: R/interp.barycentric.R

Description

ND barycentric interpolation at points Xi for a function with values f measured at locations X

Usage

1

Arguments

X

An n-by-d matrix. The rows of x represent n points in d-dimensional space.

f

A vector of values nrow(X) long to be interpolated.

Xi

An ni-by-d matrix. The rows of xi represent n points in d-dimensional space whose positions in the mesh are being sought.

Value

matrix

Author(s)

Andrew Dolman <andrew.dolman@awi.de>

References

Adapted from code here: https://dahtah.wordpress.com/2013/03/06/barycentric-interpolation-fast-interpolation-on-arbitrary-grids/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
n <- 100
df <- data.frame(x = runif(n, -1, 1), y = runif(n, -1, 1), z = runif(n, -1, 1))
df$v <- with(df, 2*x + 1*y^2 + 3*z)
df.reg <- with(df, expand.grid(x = seq(min(x), max(x), length.out = 5),
                               y = seq(min(y), max(y), length.out = 5),
                               z = seq(min(z), max(z), length.out = 5)
))

out <- InterpBarycentric(X = df[,c(1,2,3)],
                          f = df$v,
                          Xi = df.reg)

out <- as.data.frame(out)

out$v_true <-  with(out, 2*x + 1*y^2 + 3*z)

plot(v~v_true, data = out)
abline(0, 1)

hist(out$v - out$v_true)

EarthSystemDiagnostics/ecustools documentation built on Jan. 15, 2022, 5:22 p.m.