E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02AKF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E02AKF evaluates a polynomial from its Chebyshev series representation, allowing an arbitrary index increment for accessing the array of coefficients.

## 2  Specification

 SUBROUTINE E02AKF ( NP1, XMIN, XMAX, A, IA1, LA, X, RESULT, IFAIL)
 INTEGER NP1, IA1, LA, IFAIL REAL (KIND=nag_wp) XMIN, XMAX, A(LA), X, RESULT

## 3  Description

If supplied with the coefficients ${a}_{i}$, for $\mathit{i}=0,1,\dots ,n$, of a polynomial $p\left(\stackrel{-}{x}\right)$ of degree $n$, where
 $px-=12a0+a1T1x-+⋯+anTnx-,$
E02AKF returns the value of $p\left(\stackrel{-}{x}\right)$ at a user-specified value of the variable $x$. Here ${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\stackrel{-}{x}$. It is assumed that the independent variable $\stackrel{-}{x}$ in the interval $\left[-1,+1\right]$ was obtained from your original variable $x$ in the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$ by the linear transformation
 $x-=2x-xmax+xmin xmax-xmin .$
The coefficients ${a}_{i}$ may be supplied in the array A, with any increment between the indices of array elements which contain successive coefficients. This enables the routine to be used in surface fitting and other applications, in which the array might have two or more dimensions.
The method employed is based on the three-term recurrence relation due to Clenshaw (see Clenshaw (1955)), with modifications due to Reinsch and Gentleman (see Gentleman (1969)). For further details of the algorithm and its use see Cox (1973) and 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 (1973) A data-fitting package for the non-specialist user NPL Report NAC 40 National Physical Laboratory
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  Parameters

1:     NP1 – INTEGERInput
On entry: $n+1$, where $n$ is the degree of the given polynomial $p\left(\stackrel{-}{x}\right)$.
Constraint: ${\mathbf{NP1}}\ge 1$.
2:     XMIN – REAL (KIND=nag_wp)Input
3:     XMAX – REAL (KIND=nag_wp)Input
On entry: the lower and upper end points respectively of the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$. The Chebyshev series representation is in terms of the normalized variable $\stackrel{-}{x}$, where
 $x-=2x-xmax+xmin xmax-xmin .$
Constraint: ${\mathbf{XMIN}}<{\mathbf{XMAX}}$.
4:     A(LA) – REAL (KIND=nag_wp) arrayInput
On entry: the Chebyshev coefficients of the polynomial $p\left(\stackrel{-}{x}\right)$. Specifically, element $\mathit{i}×{\mathbf{IA1}}+1$ must contain the coefficient ${a}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$. Only these $n+1$ elements will be accessed.
5:     IA1 – INTEGERInput
On entry: the index increment of A. Most frequently, the Chebyshev coefficients are stored in adjacent elements of A, and IA1 must be set to $1$. However, if, for example, they are stored in ${\mathbf{A}}\left(1\right),{\mathbf{A}}\left(4\right),{\mathbf{A}}\left(7\right),\dots \text{}$, then the value of IA1 must be $3$.
Constraint: ${\mathbf{IA1}}\ge 1$.
6:     LA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which E02AKF is called.
Constraint: ${\mathbf{LA}}\ge \left({\mathbf{NP1}}-1\right)×{\mathbf{IA1}}+1$.
7:     X – REAL (KIND=nag_wp)Input
On entry: the argument $x$ at which the polynomial is to be evaluated.
Constraint: ${\mathbf{XMIN}}\le {\mathbf{X}}\le {\mathbf{XMAX}}$.
8:     RESULT – REAL (KIND=nag_wp)Output
On exit: the value of the polynomial $p\left(\stackrel{-}{x}\right)$.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ 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 parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NP1}}<1$, or ${\mathbf{IA1}}<1$, or ${\mathbf{LA}}\le \left({\mathbf{NP1}}-1\right)×{\mathbf{IA1}}$, or ${\mathbf{XMIN}}\ge {\mathbf{XMAX}}$.
${\mathbf{IFAIL}}=2$
X does not satisfy the restriction ${\mathbf{XMIN}}\le {\mathbf{X}}\le {\mathbf{XMAX}}$.

## 7  Accuracy

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

The time taken is approximately proportional to $n+1$.

## 9  Example

Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval $\left[-0.5,2.5\right]$. The following program evaluates the polynomial at $4$ equally spaced points over the interval. (For the purposes of this example, XMIN, XMAX and the Chebyshev coefficients are supplied in DATA statements. Normally a program would first read in or generate data and compute the fitted polynomial.)

### 9.1  Program Text

Program Text (e02akfe.f90)

None.

### 9.3  Program Results

Program Results (e02akfe.r)