Multilinear interpolation on an arbitrary Cartesian product.
Further arguments to the function, if
Array or function. Function values on a grid, or the function
itself. If it is the values, the
A list. Each element is a vector of ordered grid-points for a dimension. These need not be Chebyshev-knots, nor evenly spaced.
fun <- mlappx(val,grid) creates a multilinear interpolant on
the grid. The value on the grid points will be exact, the value between the
grid points is a convex combination of the values in the corners of the
hypercube surrounding it.
val is a function it will be evaluated on the grid.
function(x) defined on the hypercube, approximating the
given function. The function yields values for arguments outside the
hypercube as well, as a linear extension.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## Not run: ## evenly spaced grid-points su <- seq(0,1,length.out=10) ## irregularly spaced grid-points s <- su^3 ## create approximation on the irregularly spaced grid ml1 <- Vectorize(mlappx(exp,list(s))) ## test it, since exp is convex, the linear approximation lies above ## the exp between the grid points ml1(su) - exp(su) ## multi linear approx f <- function(x) exp(sum(x^2)) grid <- list(s,su) ml2 <- mlappx(evalongrid(f,grid=grid),grid) # an equivalent would be ml2 <- mlappx(f,grid) a <- runif(2); ml2(a); f(a) # we also get an approximation outside of the domain, of disputable quality ml2(c(1,2)); f(c(1,2)) ## End(Not run)
 0.0000000000 0.0007963441 0.0023666771 0.0036681447 0.0028930495  0.0111173403 0.0064666457 0.0191999204 0.0246303860 0.0000000000  3.563118  3.36368  19.97883  148.4132
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.