e02 Chapter Contents
e02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_1d_cheb_eval (e02aec)

## 1  Purpose

nag_1d_cheb_eval (e02aec) evaluates a polynomial from its Chebyshev series representation.

## 2  Specification

 #include #include
 void nag_1d_cheb_eval (Integer nplus1, const double a[], double xcap, double *p, NagError *fail)

## 3  Description

nag_1d_cheb_eval (e02aec) evaluates the polynomial
 $1 2 a 1 T 0 x - + a 2 T 1 x - + a 3 T 2 x - + ⋯ + a n+1 T n x -$
for any value of $\stackrel{-}{x}$ satisfying $-1\le \stackrel{-}{x}\le 1$. Here ${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\stackrel{-}{x}$. The value of $n$ is prescribed by you.
In practice, the variable $\stackrel{-}{x}$ will usually have been obtained from an original variable $x$, where ${x}_{\mathrm{min}}\le x\le {x}_{\mathrm{max}}$ and
 $x - = x-x min - x max - x x max - x min$
Note that this form of the transformation should be used computationally rather than the mathematical equivalent
 $x - = 2 x - x min - x max x max - x min$
since the former guarantees that the computed value of $\stackrel{-}{x}$ differs from its true value by at most $4\epsilon$, where $\epsilon$ is the machine precision, whereas the latter has no such guarantee.
The method employed is based upon 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), 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 (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:     nplus1IntegerInput
On entry: the number $n+1$ of terms in the series (i.e., one greater than the degree of the polynomial).
Constraint: ${\mathbf{nplus1}}\ge 1$.
2:     a[nplus1]const doubleInput
On entry: ${\mathbf{a}}\left[\mathit{i}-1\right]$ must be set to the value of the $\mathit{i}$th coefficient in the series, for $\mathit{i}=1,2,\dots ,n+1$.
3:     xcapdoubleInput
On entry: $\stackrel{-}{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 8) to allow for possible rounding errors committed in the transformation from $x$ to $\stackrel{-}{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 ${x}_{\mathrm{min}}$ to ${x}_{\mathrm{max}}$.
4:     pdouble *Output
On exit: the value of the polynomial.
5:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT_ARG_LT
On entry, nplus1 must not be less than 1: ${\mathbf{nplus1}}=〈\mathit{\text{value}}〉$.
NE_INVALID_XCAP
On entry, $\mathrm{abs}\left({\mathbf{xcap}}\right)>1.0+4\epsilon$, where $\epsilon$ is the machine precision.
In this case the value of p is set arbitrarily to zero.

## 7  Accuracy

The rounding errors committed are such that the computed value of the polynomial is exact for a slightly perturbed set of coefficients ${a}_{i}+\delta {a}_{i}$. The ratio of the sum of the absolute values of the $\delta {a}_{i}$ to the sum of the absolute values of the ${a}_{i}$ is less than a small multiple of $\left(n+1\right)×$ machine precision.

The time taken by nag_1d_cheb_eval (e02aec) is approximately proportional to $n+1$.
It is expected that a common use of nag_1d_cheb_eval (e02aec) will be the evaluation of the polynomial approximations produced by nag_1d_cheb_fit (e02adc) and nag_1d_cheb_interp_fit (e02afc).

## 9  Example

Evaluate at 11 equally-spaced points in the interval $-1\le \stackrel{-}{x}\le 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 $-1\le \stackrel{-}{x}\le 1$. The program is self-starting in that any number of datasets can be supplied.

### 9.1  Program Text

Program Text (e02aece.c)

### 9.2  Program Data

Program Data (e02aece.d)

### 9.3  Program Results

Program Results (e02aece.r)