# chebappxg: Interpolation on a non-Chebyshev grid In chebpol: Multivariate Interpolation

## Description

A poor-man's approximation on non-Chebyshev grids. If you for some reason can't evaluate your function on a Chebyshev-grid, but instead have some other grid which still is a Cartesian product of one-dimensional grids, you may use this function to create an interpolation.

## Usage

 ```1 2 3``` ```chebappxg(...) chebappxgf(...) ```

## Arguments

 `...` Further arguments to `fun`. `val` Array. Function values on a grid. `grid` A list. Each element is a sorted vector of grid-points for a dimension. These need not be Chebyshev-knots, nor evenly spaced. `fun` The function to be approximated. `mapdim` Deprecated.

## Details

A call `fun <- chebappxg(val,grid)` does the following. A Chebyshev interpolation `ch` for `val` is created, on the [-1,1] hypercube. For each dimension a grid-map function `gm` is created which maps the grid-points monotonically into Chebyshev knots. For this, the function `splinefun` with `method='hyman'` is used. When `fun(x)` is called, it translates to `ch(gm(x))`. For uniform grids, the function `ucappx` will produce a faster interpolation in that a closed form `gm` is used.

`chebappxgf` is used if the function, rather than its values, is available. The function will be evaluated on the grid.

Even though this approach works in simple cases it is not a panacea. The grid in each dimension should probably not be too irregularly spaced. I.e. short and long gaps interspersed is likely to cause problems.

## Value

A `function(x)` defined on the hypercube, approximating the given function.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35``` ```## 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 ch <- Vectorize(chebappxg(exp(s),list(s))) ## test it: ch(su) - exp(su) # try one with three variables f <- function(x) exp(-sum(x^2)) grid <- list(s,su,su^2) ch2 <- chebappxg(evalongrid(f,grid=grid),grid) # test it at 10 random points replicate(10,{a<-runif(3); ch2(a)-f(a)}) # Try Runge's function on a uniformly spaced grid. # Ordinary polynomial fitting of high degree of Runge's function on a uniform grid # creates large oscillations near the end of the interval. Not so with chebappxgf f <- function(x) 1/(1+25*x^2) chg <- Vectorize(chebappxgf(f,seq(-1,1,length.out=15))) # also compare with Chebyshev interpolation ch <- Vectorize(chebappxf(f,15)) \dontrun{ # plot it s <- seq(-1,1,length.out=200) plot(s, f(s), type='l', col='black') lines(s, chg(s), col='blue') lines(s, ch(s), col='red') legend('topright', legend=c('Runge function','chebappxg on uniform grid','Chebyshev'), col=c('black','blue','red'), lty=1) } ## End(Not run) ```

chebpol documentation built on Dec. 9, 2019, 5:08 p.m.