Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_1dcheb_eval (e02ae)

## Purpose

nag_fit_1dcheb_eval (e02ae) evaluates a polynomial from its Chebyshev series representation.

## Syntax

[p, ifail] = e02ae(a, xcap, 'nplus1', nplus1)
[p, ifail] = nag_fit_1dcheb_eval(a, xcap, 'nplus1', nplus1)

## Description

nag_fit_1dcheb_eval (e02ae) evaluates the polynomial
 (1/2)a1T0(x) + a2T1(x) + a3T2(x) + ⋯ + an + 1Tn(x) $12a1T0(x-)+a2T1(x-)+a3T2(x-)+⋯+an+1Tn(x-)$
for any value of x$\stackrel{-}{x}$ satisfying 1x1$-1\le \stackrel{-}{x}\le 1$. Here Tj(x)${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree j$j$ with argument x$\stackrel{-}{x}$. The value of n$n$ is prescribed by you.
In practice, the variable x$\stackrel{-}{x}$ will usually have been obtained from an original variable x$x$, where xminxxmax${x}_{\mathrm{min}}\le x\le {x}_{\mathrm{max}}$ and
 x = (((x − xmin) − (xmax − x)))/((xmax − xmin)) $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)) $x-= (2x-xmin-xmax) (xmax-xmin)$
since the former guarantees that the computed value of x$\stackrel{-}{x}$ differs from its true value by at most 4ε$4\epsilon$, where ε$\epsilon$ 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).

## 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

## Parameters

### Compulsory Input Parameters

1:     a(nplus1) – double array
nplus1, the dimension of the array, must satisfy the constraint nplus11${\mathbf{nplus1}}\ge 1$.
a(i)${\mathbf{a}}\left(\mathit{i}\right)$ must be set to the value of the i$\mathit{i}$th coefficient in the series, for i = 1,2,,n + 1$\mathit{i}=1,2,\dots ,n+1$.
2:     xcap – double scalar
x$\stackrel{-}{x}$, the argument at which the polynomial is to be evaluated. It should lie in the range 1$-1$ to + 1$+1$, but a value just outside this range is permitted (see Section [Error Indicators and Warnings]) to allow for possible rounding errors committed in the transformation from x$x$ to x$\stackrel{-}{x}$ discussed in Section [Description]. Provided the recommended form of the transformation is used, a successful exit is thus assured whenever the value of x$x$ lies in the range xmin${x}_{\mathrm{min}}$ to xmax${x}_{\mathrm{max}}$.

### Optional Input Parameters

1:     nplus1 – int64int32nag_int scalar
Default: The dimension of the array a.
The number n + 1$n+1$ of terms in the series (i.e., one greater than the degree of the polynomial).
Constraint: nplus11${\mathbf{nplus1}}\ge 1$.

None.

### Output Parameters

1:     p – double scalar
The value of the polynomial.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
ABS(xcap) > 1.0 + 4ε$\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.
ifail = 2${\mathbf{ifail}}=2$
 On entry, nplus1 < 1${\mathbf{nplus1}}<1$.

## Accuracy

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

The time taken is approximately proportional to n + 1$n+1$.
It is expected that a common use of nag_fit_1dcheb_eval (e02ae) will be the evaluation of the polynomial approximations produced by nag_fit_1dcheb_arb (e02ad) and nag_fit_1dcheb_glp (e02af).

## Example

```function nag_fit_1dcheb_eval_example
a = [2;
0.5;
0.25;
0.125;
0.0625];
xcap = -1;
[p, ifail] = nag_fit_1dcheb_eval(a, xcap)
```
```

p =

0.6875

ifail =

0

```
```function e02ae_example
a = [2;
0.5;
0.25;
0.125;
0.0625];
xcap = -1;
[p, ifail] = e02ae(a, xcap)
```
```

p =

0.6875

ifail =

0

```