The package contains methods for creating multivariate/multidimensional interpolations for real-valued functions on hypercubes. The methods include classical Chebyshev interpolation, multilinear and Floater-Hormann for arbitrary Cartesian product grids, and simplex linear and polyharmonic spline for scattered multi dimensional data.
The primary method of the package is
dispatches to some other method. All the generated
interpolants accept as an argument a matrix of column
vectors. The generated functions also accept an argument
threads=getOption('chebpol.threads') to utilize more than
one CPU if a matrix of column vectors is evaluated. The option
chebpol.threads is initialized from the environment variable
CHEBPOL_THREADS upon loading of the package. It defaults to
The interpolants are ordinary R-objects and can be saved with
save() and loaded
load() or serialized/unserialized with other tools, just like any R-object.
However, they contain calls to functions in the package, and while the author will make efforts
to ensure that generated interpolants are compatible with future versions of chebpol,
I can issue no such absolute guarantee.
If we are free to evaluate the function to interpolate in arbitrary points, we can use
a Chebyshev interpolation. The classical one is available with
There are several options if your function must be evaluated in a uniform grid.
There is the Floater-Hormann rational interpolation available with
There is a transformed Chebyshev variant
For grids which are not uniform, but still Cartesian products of one-dimensional grids,
there is the Floater-Hormann interpolation
ipol(...,method='fh'), and a transformed
ipol(...,method='general'), as well as a multilinear
ipol(...,method='multilinear'). These methods work on uniform grids as well.
There is also a
method='stalker' which is a shape preserving spline, and a variant
method='hstalker'. Both are described in a vignette. These splines in one dimension
attempts to honour monotonicity and local extrema, in particular the
positivity-preserving in the sense that it will preserve maxima and minima.
For scattered data, not necessarily organised as a Cartesian product grid, there is
a simplex linear interpolation available with
and a polyharmonic spline with
There are also functions for producing Chebyshev grids
chebknots) as well as a function for evaluating a
function on a grid (
evalongrid), and a function for finding
the Chebyshev coefficients (
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## make some function values on a 50x50x50 grid dims <- c(x=50,y=50,z=50) f <- function(x) sqrt(1+x)*exp(x)*sin(5*x)^2 value <- evalongrid(f , dims) ##fit a Chebyshev approximation to it. Note that the value-array contains the ##grid-structure. ch <- ipol(value,method='cheb') ## To see the full grid, use the chebknots function and expand.grid ## Not run: head(cbind(expand.grid(chebknots(dims)), value=as.numeric(value), appx=as.numeric(evalongrid(ch,dims)))) ## End(Not run) ## Make a Floater-Hormann approximation on a uniform grid as well fh <- ipol(f,grid=lapply(dims,function(n) seq(-1,1,length.out=n)),method='fh',k=5) ## evaluate in some random points in R3 m <- matrix(runif(15,-1,1),3) rbind(true=apply(m,2,f), cheb=ch(m), fh=fh(m))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.