hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_fit_1dcheb_glp (e02af)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_fit_1dcheb_glp (e02af) 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.


[a, ifail] = e02af(f, 'nplus1', nplus1)
[a, ifail] = nag_fit_1dcheb_glp(f, 'nplus1', nplus1)


nag_fit_1dcheb_glp (e02af) computes the coefficients aj, for j=1,2,,n+1, in the Chebyshev series
which interpolates the data fr at the points
x-r=cosr-1π/n ,  r=1,2,,n+1.  
Here Tjx- 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 the data abscissae can be chosen by you, 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 fr are to be provided are
xr=12xmax-xmincosπr-1/n+12xmax+xmin,  r=1,2,,n+1  
where xmax and xmin 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 ai+1, say, yields a least squares approximation to the data. This approximation, px-, say, is the polynomial of degree i which minimizes
where the residual εr=px-r-fr, 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) and Cox and Hayes (1973).
Subsequent evaluation of the computed polynomial, perhaps truncated after an appropriate number of terms, should be carried out using nag_fit_1dcheb_eval (e02ae).


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


Compulsory Input Parameters

1:     fnplus1 – double array
For r=1,2,,n+1, fr must contain fr the value of the dependent variable (ordinate) corresponding to the value
of the independent variable (abscissa) x-, or equivalently to the value
of your original variable x. Here xmax and xmin are respectively the upper and lower ends of the range over which you wish to interpolate.

Optional Input Parameters

1:     nplus1 int64int32nag_int scalar
Default: the dimension of the array f.
The number n+1 of data points (one greater than the degree n of the interpolating polynomial).
Constraint: nplus12.

Output Parameters

1:     anplus1 – double array
aj is the coefficient aj in the interpolating polynomial, for j=1,2,,n+1.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,nplus1<2.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


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

Further Comments

The time taken is approximately proportional to n+1 2+30.
For choice of degree when using the function for least squares approximation, see Polynomial Curves in the E02 Chapter Introduction.


Determine the Chebyshev coefficients of the polynomial which interpolates the data x-r,fr, for r=1,2,,11, where x-r=cosπ×r-1/10 and fr=ex-r. Evaluate, for comparison with the values of fr, 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_fit_1dcheb_eval (e02ae) is used to evaluate the interpolating polynomial. The program is self-starting in that any number of datasets can be supplied.
function e02af_example

fprintf('e02af example results\n\n');

x = -cos([0:10]*pi/10);
f = exp(-x);

[a, ifail] = e02af(f);

disp('Chebyshev coefficients:');

for i=1:11
  [p(i), ifail] = e02ae(a, -x(i));
disp('      x        p(x)');
disp([x' p']);

e02af example results

Chebyshev coefficients:

      x        p(x)
   -1.0000    2.7183
   -0.9511    2.5884
   -0.8090    2.2457
   -0.5878    1.8000
   -0.3090    1.3621
   -0.0000    1.0000
    0.3090    0.7342
    0.5878    0.5556
    0.8090    0.4453
    0.9511    0.3863
    1.0000    0.3679

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015