NAG CL Interface
e02akc (dim1_​cheb_​eval2)

Settings help

CL Name Style:


1 Purpose

e02akc evaluates a polynomial from its Chebyshev series representation, allowing an arbitrary index increment for accessing the array of coefficients.

2 Specification

#include <nag.h>
void  e02akc (Integer n, double xmin, double xmax, const double a[], Integer ia1, double x, double *result, NagError *fail)
The function may be called by the names: e02akc, nag_fit_dim1_cheb_eval2 or nag_1d_cheb_eval2.

3 Description

If supplied with the coefficients ai, for i=0,1,,n, of a polynomial p(x¯) of degree n, where
p(x¯)=12a0+a1T1(x¯)++anTn(x¯),  
e02akc returns the value of p(x¯) at a user-specified value of the variable x. Here Tj(x¯) denotes the Chebyshev polynomial of the first kind of degree j with argument x¯. It is assumed that the independent variable x¯ in the interval [−1,+1] was obtained from your original variable x in the interval [xmin,xmax] by the linear transformation
x¯=2x-(xmax+xmin) xmax-xmin .  
The coefficients ai may be supplied in the array a, with any increment between the indices of array elements which contain successive coefficients. This enables the function to be used in surface fitting and other applications, in which the array might have two or more dimensions.
The method employed is based on the three-term recurrence relation due to Clenshaw (see Clenshaw (1955)), with modifications due to Reinsch and Gentleman (see Gentleman (1969)). For further details of the algorithm and its use see Cox (1973) and Cox and Hayes (1973).

4 References

Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
Cox M G (1973) A data-fitting package for the non-specialist user NPL Report NAC 40 National Physical Laboratory
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
Gentleman W M (1969) An error analysis of Goertzel's (Watt's) method for computing Fourier coefficients Comput. J. 12 160–165

5 Arguments

1: n Integer Input
On entry: n, the degree of the given polynomial p(x¯).
Constraint: n0.
2: xmin double Input
3: xmax double Input
On entry: the lower and upper end points respectively of the interval [xmin,xmax]. The Chebyshev series representation is in terms of the normalized variable x¯, where
x¯=2x-(xmax+xmin) xmax-xmin .  
Constraint: xmin<xmax.
4: a[dim] const double Input
Note: the dimension, dim, of the array a must be at least ((1-1)×ia1+1n×ia1+1).
On entry: the Chebyshev coefficients of the polynomial p(x¯). Specifically, element i×ia1 must contain the coefficient ai, for i=0,1,,n. Only these n+1 elements will be accessed.
5: ia1 Integer Input
On entry: the index increment of a. Most frequently, the Chebyshev coefficients are stored in adjacent elements of a, and ia1 must be set to 1. However, if, for example, they are stored in a[0],a[3],a[6],, the value of ia1 must be 3.
Constraint: ia11.
6: x double Input
On entry: the argument x at which the polynomial is to be evaluated.
Constraint: xminxxmax.
7: result double * Output
On exit: the value of the polynomial p(x¯).
8: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, ia1=value.
Constraint: ia11.
On entry, n+1=value>.
Constraint: n0.
On entry, n=value.
Constraint: n0.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_2
On entry, xmax=value and xmin=value.
Constraint: xmax>xmin.
NE_REAL_3
On entry, x does not lie in [xmin,xmax]: x=value, xmin=value and xmax=value.

7 Accuracy

The rounding errors are such that the computed value of the polynomial is exact for a slightly perturbed set of coefficients ai+δai. The ratio of the sum of the absolute values of the δai to the sum of the absolute values of the ai is less than a small multiple of (n+1)×machine precision.

8 Parallelism and Performance

e02akc is not threaded in any implementation.

9 Further Comments

The time taken is approximately proportional to n+1.

10 Example

Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval [-0.5,2.5]. The following program evaluates the polynomial at 4 equally spaced points over the interval. (For the purposes of this example, xmin, xmax and the Chebyshev coefficients are supplied . Normally a program would first read in or generate data and compute the fitted polynomial.)

10.1 Program Text

Program Text (e02akce.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (e02akce.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 0.5 1 1.5 2 2.5 3 −0.5 0 0.5 1 1.5 2 2.5 P(x) x Example Program Evaluation of Chebyshev Representation of Polynomial gnuplot_plot_1