chebeval: Evaluate a Chebyshev interpolation in a point

Description Usage Arguments Value Examples

View source: R/chebyshev.R

Description

Given Chebyshev coefficients, evaluate the interpolation in a point.

Usage

1
2
chebeval(x, coef, intervals = NULL,
  threads = getOption("chebpol.threads"))

Arguments

x

The point to evaluate.

coef

The Chebyshev coefficients. Typically from a call to chebcoef, possibly modified.

intervals

A list of minimum and maximum values. One for each dimension of the hypercube.

threads

And integer. In case x is a matrix of column vectors, use this number of threads in parallel to evaluate.

Value

A numeric. The interpolated value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# make a function which is known to be unsuitable for Chebyshev approximation
f <- function(x) sign(x)
# make a standard Chebyshev interpolation
ch <- ipol(f,dims=50,method='chebyshev')
# then do a truncated interpolation
val <- evalongrid(f,50)
coef <- chebcoef(val)
# truncate the high frequencies
coef[-(1:10)] <- 0
# make a truncated approximation
tch <- Vectorize(function(x) chebeval(x,coef))
# make a lower degree also
ch2 <- ipol(f,dims=10,method='chebyshev')
# plot the functions
## Not run: 
s <- seq(-1,1,length.out=400)
plot(s,ch(s),col='red',type='l')
lines(s,tch(s),col='blue')
lines(s,f(s))
lines(s,ch2(s),col='green')

## End(Not run)

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