NAG FL Interface
e02aff (dim1_​cheb_​glp)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e02aff 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.

2 Specification

Fortran Interface
Subroutine e02aff ( nplus1, f, a, ifail)
Integer, Intent (In) :: nplus1
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: f(nplus1)
Real (Kind=nag_wp), Intent (Out) :: a(nplus1)
C Header Interface
#include <nag.h>
void  e02aff_ (const Integer *nplus1, const double f[], double a[], Integer *ifail)
The routine may be called by the names e02aff or nagf_fit_dim1_cheb_glp.

3 Description

e02aff computes the coefficients aj, for j=1,2,,n+1, in the Chebyshev series
12a1T0(x¯)+a2T1(x¯)+a3T2(x¯)++an+1Tn(x¯),  
which interpolates the data fr at the points
x¯r=cos((r-1)π/n) ,  r=1,2,,n+1.  
Here Tj(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 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=12(xmax-xmin)cos(π(r-1)/n)+12(xmax+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, p(x¯), say, is the polynomial of degree i which minimizes
12ε12+ε22+ε32++εn2+12εn+12,  
where the residual εr=p(x¯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 e02aef.

4 References

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

5 Arguments

1: nplus1 Integer Input
On entry: the number n+1 of data points (one greater than the degree n of the interpolating polynomial).
Constraint: nplus12.
2: f(nplus1) Real (Kind=nag_wp) array Input
On entry: for r=1,2,,n+1, f(r) must contain fr 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)=12(xmax-xmin)cos(π(r-1)/n)+12(xmax+xmin)  
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.
3: a(nplus1) Real (Kind=nag_wp) array Output
On exit: a(j) is the coefficient aj in the interpolating polynomial, for j=1,2,,n+1.
4: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, nplus1=value.
Constraint: nplus12.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e02aff is not threaded in any implementation.

9 Further Comments

The time taken is approximately proportional to (n+1) 2+30.
For choice of degree when using the routine for least squares approximation, see Section 3.2 in the E02 Chapter Introduction.

10 Example

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 e02aef is used to evaluate the interpolating polynomial. The program is self-starting in that any number of datasets can be supplied.

10.1 Program Text

Program Text (e02affe.f90)

10.2 Program Data

Program Data (e02affe.d)

10.3 Program Results

Program Results (e02affe.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 0 0.5 1 1.5 2 2.5 −1 −0.5 0 0.5 1 5x10−5 0.0001 0.00015 Chebyshev polynomial fit |exP(x)| P(x) |exP(x)| (error) x gnuplot_plot_1 points on polynomial gnuplot_plot_3 Example Program Interpolating Chebyshev Polynomial