# NAG FL Interfacee02akf (dim1_​cheb_​eval2)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02akf ( np1, xmin, xmax, a, ia1, la, x,
 Integer, Intent (In) :: np1, ia1, la Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xmin, xmax, a(la), x Real (Kind=nag_wp), Intent (Out) :: result
#include <nag.h>
 void e02akf_ (const Integer *np1, const double *xmin, const double *xmax, const double a[], const Integer *ia1, const Integer *la, const double *x, double *result, Integer *ifail)
The routine may be called by the names e02akf or nagf_fit_dim1_cheb_eval2.

## 3Description

If supplied with the coefficients ${a}_{i}$, for $\mathit{i}=0,1,\dots ,n$, of a polynomial $p\left(\overline{x}\right)$ of degree $n$, where
 $p(x¯)=12a0+a1T1(x¯)+⋯+anTn(x¯),$
e02akf returns the value of $p\left(\overline{x}\right)$ at a user-specified value of the variable $x$. Here ${T}_{j}\left(\overline{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\overline{x}$. It is assumed that the independent variable $\overline{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).
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

## 5Arguments

1: $\mathbf{np1}$Integer Input
On entry: $n+1$, where $n$ is the degree of the given polynomial $p\left(\overline{x}\right)$.
Constraint: ${\mathbf{np1}}\ge 1$.
2: $\mathbf{xmin}$Real (Kind=nag_wp) Input
3: $\mathbf{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 $\overline{x}$, where
 $x¯=2x-(xmax+xmin) xmax-xmin .$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
4: $\mathbf{a}\left({\mathbf{la}}\right)$Real (Kind=nag_wp) array Input
On entry: the Chebyshev coefficients of the polynomial $p\left(\overline{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: $\mathbf{ia1}$Integer Input
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{}$, the value of ia1 must be $3$.
Constraint: ${\mathbf{ia1}}\ge 1$.
6: $\mathbf{la}$Integer Input
On entry: the dimension of the array a as declared in the (sub)program from which e02akf is called.
Constraints:
• ${\mathbf{la}}\ge \left({\mathbf{np1}}-1\right)×{\mathbf{ia1}}+1$.
7: $\mathbf{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: $\mathbf{result}$Real (Kind=nag_wp) Output
On exit: the value of the polynomial $p\left(\overline{x}\right)$.
9: $\mathbf{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 $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ia1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ia1}}\ge 1$.
On entry, ${\mathbf{la}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{np1}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ia1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{la}}>\left({\mathbf{np1}}-1\right)×{\mathbf{ia1}}$.
On entry, ${\mathbf{np1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{np1}}\ge 1$.
On entry, ${\mathbf{xmax}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
${\mathbf{ifail}}=2$
On entry, x does not lie in $\left[{\mathbf{xmin}},{\mathbf{xmax}}\right]$: ${\mathbf{x}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{xmin}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmax}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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 .

## 8Parallelism and Performance

e02akf is not threaded in any implementation.

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

## 10Example

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

### 10.1Program Text

Program Text (e02akfe.f90)

None.

### 10.3Program Results

Program Results (e02akfe.r)