R: Interpolation on a uniform grid

ucappx {chebpol} | R Documentation

## Interpolation on a uniform grid

### Description

A poor-man's approximation on uniform grids. If you for some reason can't evaluate your function on a Chebyshev-grid, but instead have a uniform grid, you may use this function to create an interpolation.

### Usage

    ucappx(...)

    ucappxf(...)

### Arguments

`...` | Further arguments to `fun`.
`val` | Array. Function values on a grid.
`intervals` | List of vectors of length two. Specifying the hypercube extent in each dimension
`fun` | Function to be interpolated.
`dims` | Integer. Number of grid points in each dimension.

### Details

This does about the same as `chebappxg` for unform grids, though no grid map function is constructed, as a fixed such function is used.

A Chebyshev-interpolation `ch` is made for `val` with `chebappx`. Upon evaluation the uniform grid in each dimension is mapped differentiably to the Chebyshev-knots so that `ch` is evaluated in sin(0.5*pi*x*(1-n)/n) where `n` is the number of knots in the dimension, possibly after `x` has been remapped from the hypercube interval to [-1,1].

Thus, the interpolation is not a polynomial.

For `ucappx` the function values are provided, the number of grid points in each dimension is to be found in `dim(val)`. For `ucappxf` the function to be interpolated is `fun`, and the number of grid points is passed in `dims`.

As the example shows, this approximation is better than the Chebyshev approximation for some functions.

### Value

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

### Examples

    ## Not run:
    # Runge function
    f <- function(x) 1/(1+25*x^2)
    grid <- seq(-1,1,length.out=15)
    val <- f(grid)
    uc <- Vectorize(ucappx(val))
    # and the Chebyshev
    ch <- Vectorize(chebappxf(f,15))
    # test it at 10 random points
    t(replicate(10,{a<-runif(1,-1,1); c(arg=a, uc=uc(a), true=f(a), cheb=ch(a))}))

    ## End(Not run)

[Package chebpol version 2.1-2 Index]