Learn R Programming

chebpol (version 1.3-952)

chebeval: Evaluate a Chebyshev interpolation in a point

Description

Given Chebyshev coefficients, evaluate the interpolation in a point.

Usage

chebeval(x, coef, intervals=NULL)

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.

Value

  • A numeric. The interpolated value.

Examples

Run this code
# make a function which is known to be unsuitable for Chebyshev approximation
f <- function(x) sign(x)
# make a standard Chebyshev interpolation
ch <- Vectorize(chebappxf(f,50))
# 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 <- Vectorize(chebappxf(f,10))
# plot the functions
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')

Run the code above in your browser using DataLab