NAG C Library Function Document

nag_1d_cheb_interp_fit (e02afc)


nag_1d_cheb_interp_fit (e02afc) computes the coefficients of a polynomial, in its Chebyshev series form, which interpolates (passes exactly through) data at a special set of points. Least squares polynomial approximations can also be obtained.


#include <nag.h>
#include <nage02.h>
void  nag_1d_cheb_interp_fit (Integer nplus1, const double f[], double a[], NagError *fail)


nag_1d_cheb_interp_fit (e02afc) computes the coefficients a j , for j=1,2,,n + 1, in the Chebyshev series
1 2 a 1 T 0 x - + a 2 T 1 x - + a 3 T 2 x - + + a n+1 T n x - ,  
which interpolates the data f r  at the points
x - r = cos r-1 π / n , r = 1 , 2 , , n + 1 .  
Here T j x -  denotes the Chebyshev polynomial of the first kind of degree j  with argument x - . The use of these points minimizes the risk of unwanted fluctuations in the polynomial and is recommended when you can choose the data abscissae, e.g., when the data is given as a graph. For further advantages of this choice of points, see Clenshaw (1962).
In terms of your original variables, x  say, the values of x  at which the data f r  are to be provided are
x r = 1 2 x max - x min cos r-1 π / n + 1 2 x max + x min ,   r = 1 , 2 , , n + 1  
where x max  and x min  are respectively the upper and lower ends of the range of x  over which you wish to interpolate.
Truncation of the resulting series after the term involving a i+1 , say, yields a least squares approximation to the data. This approximation, p x - , say, is the polynomial of degree i  which minimizes
1 2 ε 1 2 + ε 2 2 + ε 3 2 + + ε n 2 + 1 2 ε n+1 2 ,  
where the residual ε r = p x - r - f r , for r=1,2,,n + 1.
The method employed is based on the application of the three-term recurrence relation due to Clenshaw (1955) for the evaluation of the defining expression for the Chebyshev coefficients (see, for example, Clenshaw (1962)). The modifications to this recurrence relation suggested by Reinsch and Gentleman (see Gentleman (1969)) are used to give greater numerical stability.
For further details of the algorithm and its use see Cox (1974), Cox and Hayes (1973).
Subsequent evaluation of the computed polynomial, perhaps truncated after an appropriate number of terms, should be carried out using nag_1d_cheb_eval (e02aec).


Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
Clenshaw C W (1962) Chebyshev Series for Mathematical Functions Mathematical tables HMSO
Cox M G (1974) A data-fitting package for the non-specialist user Software for Numerical Mathematics (ed D J Evans) Academic Press
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


1:     nplus1 IntegerInput
On entry: the number n+1  of data points (one greater than the degree n  of the interpolating polynomial).
Constraint: nplus12 .
2:     f[nplus1] const doubleInput
On entry: for r = 1 , 2 , , n + 1 , f[r-1]  must contain f r  the value of the dependent variable (ordinate) corresponding to the value
x - r = cos π r-1 n  
of the independent variable (abscissa) x - , or equivalently to the value
x r = 1 2 x max - x min cos π r-1 / n + 1 2 x max + x min  
of your original variable x . Here x max  and x min  are respectively the upper and lower ends of the range over which you wish to interpolate.
3:     a[nplus1] doubleOutput
On exit: a[j-1]  is the coefficient a j  in the interpolating polynomial, for j=1,2,,n + 1.
4:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

On entry, nplus1 must not be less than 2: nplus1=value .


The rounding errors committed are such that the computed coefficients are exact for a slightly perturbed set of ordinates f r + δ f r . The ratio of the sum of the absolute values of the δ f r  to the sum of the absolute values of the f r  is less than a small multiple of n+1 ε , where ε  is the machine precision.

Parallelism and Performance

nag_1d_cheb_interp_fit (e02afc) is not threaded in any implementation.

Further Comments

The time taken by nag_1d_cheb_interp_fit (e02afc) is approximately proportional to n+1 2 + 30 .
For choice of degree when using the function for least squares approximation, see the e02 Chapter Introduction.


Determine the Chebyshev coefficients of the polynomial which interpolates the data x - r , f r , for r=1,2,,11, where x - r = cos r-1 π / 10  and f r = e x - r . Evaluate, for comparison with the values of f r , the resulting Chebyshev series at x - r , for r=1,2,,11.
The example program supplied is written in a general form that will enable polynomial interpolations of arbitrary data at the cosine points cos r-1 π / n , for r=1,2,,n + 1 to be obtained for any n  ( = nplus1 - 1 ). Note that nag_1d_cheb_eval (e02aec) is used to evaluate the interpolating polynomial. The program is self-starting in that any number of datasets can be supplied.

Program Text

Program Text (e02afce.c)

Program Data

Program Data (e02afce.d)

Program Results

Program Results (e02afce.r)