NAG Library Routine Document

e02aef (dim1_cheb_eval)


    1  Purpose
    7  Accuracy


e02aef evaluates a polynomial from its Chebyshev series representation.


Fortran Interface
Subroutine e02aef ( nplus1, a, xcap, p, ifail)
Integer, Intent (In):: nplus1
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: a(nplus1), xcap
Real (Kind=nag_wp), Intent (Out):: p
C Header Interface
#include nagmk26.h
void  e02aef_ (const Integer *nplus1, const double a[], const double *xcap, double *p, Integer *ifail)


e02aef evaluates the polynomial
for any value of x- satisfying -1x-1. Here Tjx- denotes the Chebyshev polynomial of the first kind of degree j with argument x-. The value of n is prescribed by you.
In practice, the variable x- will usually have been obtained from an original variable x, where xminxxmax and
x-=x-xmin-xmax-x xmax-xmin  
Note that this form of the transformation should be used computationally rather than the mathematical equivalent
x-= 2x-xmin-xmax xmax-xmin  
since the former guarantees that the computed value of x- differs from its true value by at most 4ε, where ε is the machine precision, whereas the latter has no such guarantee.
The method employed is based on the three-term recurrence relation due to Clenshaw (1955), with modifications to give greater numerical stability due to Reinsch and Gentleman (see Gentleman (1969)).
For further details of the algorithm and its use see Cox (1974) and Cox and Hayes (1973).


Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
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 terms in the series (i.e., one greater than the degree of the polynomial).
Constraint: nplus11.
2:     anplus1 – Real (Kind=nag_wp) arrayInput
On entry: ai must be set to the value of the ith coefficient in the series, for i=1,2,,n+1.
3:     xcap – Real (Kind=nag_wp)Input
On entry: x-, the argument at which the polynomial is to be evaluated. It should lie in the range -1 to +1, but a value just outside this range is permitted (see Section 6) to allow for possible rounding errors committed in the transformation from x to x- discussed in Section 3. Provided the recommended form of the transformation is used, a successful exit is thus assured whenever the value of x lies in the range xmin to xmax.
4:     p – Real (Kind=nag_wp)Output
On exit: the value of the polynomial.
5:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. 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).

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:
ABSxcap>1.0+4ε, where ε is the machine precision. In this case the value of p is set arbitrarily to zero.
On entry,nplus1<1.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


The rounding errors committed 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.

Parallelism and Performance

e02aef is not threaded in any implementation.

Further Comments

The time taken is approximately proportional to n+1.
It is expected that a common use of e02aef will be the evaluation of the polynomial approximations produced by e02adf and e02aff.


Evaluate at 11 equally-spaced points in the interval -1x-1 the polynomial of degree 4 with Chebyshev coefficients, 2.0, 0.5, 0.25, 0.125, 0.0625.
The example program is written in a general form that will enable a polynomial of degree n in its Chebyshev series form to be evaluated at m equally-spaced points in the interval -1x-1. The program is self-starting in that any number of datasets can be supplied.

Program Text

Program Text (e02aefe.f90)

Program Data

Program Data (e02aefe.d)

Program Results

Program Results (e02aefe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0.6 0.8 1 1.2 1.4 1.6 1.8 2 −1 −0.5 0 0.5 1 P(x) x Example Program Points on a Degree Four Polynomial P(x) = 1+0.5T1(x)+0.25T2(x)+0.125T3(x)+0.0625T4(x) gnuplot_plot_1 gnuplot_plot_2
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017