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_eval2 (e02ak)

Purpose

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

Syntax

[result, ifail] = e02ak(n, xmin, xmax, a, ia1, x)
[result, ifail] = nag_fit_1dcheb_eval2(n, xmin, xmax, a, ia1, x)

Description

If supplied with the coefficients ai${a}_{i}$, for i = 0,1,,n$\mathit{i}=0,1,\dots ,n$, of a polynomial p(x)$p\left(\stackrel{-}{x}\right)$ of degree n$n$, where
 p(x) = (1/2)a0 + a1T1(x) + ⋯ + anTn(x), $p(x-)=12a0+a1T1(x-)+⋯+anTn(x-),$
nag_fit_1dcheb_eval2 (e02ak) returns the value of p(x)$p\left(\stackrel{-}{x}\right)$ at a user-specified value of the variable x$x$. 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}$. It is assumed that the independent variable x$\stackrel{-}{x}$ in the interval [1, + 1]$\left[-1,+1\right]$ was obtained from your original variable x$x$ in the interval [xmin,xmax]$\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$ by the linear transformation
 x = (2x − (xmax + xmin))/(xmax − xmin). $x-=2x-(xmax+xmin) xmax-xmin .$
The coefficients ai${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 function 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).

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

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the degree of the given polynomial p(x)$p\left(\stackrel{-}{x}\right)$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     xmin – double scalar
3:     xmax – double scalar
The lower and upper end points respectively of the interval [xmin,xmax]$\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$. The Chebyshev series representation is in terms of the normalized variable x$\stackrel{-}{x}$, where
 x = (2x − (xmax + xmin))/(xmax − xmin). $x-=2x-(xmax+xmin) xmax-xmin .$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
4:     a(la) – double array
la, the dimension of the array, must satisfy the constraint la(np11) × ia1 + 1$\mathit{la}\ge \left(\mathit{np1}-1\right)×{\mathbf{ia1}}+1$.
The Chebyshev coefficients of the polynomial p(x)$p\left(\stackrel{-}{x}\right)$. Specifically, element i × ia1 + 1$\mathit{i}×{\mathbf{ia1}}+1$ must contain the coefficient ai${a}_{\mathit{i}}$, for i = 0,1,,n$\mathit{i}=0,1,\dots ,n$. Only these n + 1$n+1$ elements will be accessed.
5:     ia1 – int64int32nag_int scalar
The index increment of a. Most frequently, the Chebyshev coefficients are stored in adjacent elements of a, and ia1 must be set to 1$1$. However, if, for example, they are stored in a(1),a(4),a(7),${\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$3$.
Constraint: ia11${\mathbf{ia1}}\ge 1$.
6:     x – double scalar
The argument x$x$ at which the polynomial is to be evaluated.
Constraint: ${\mathbf{xmin}}\le {\mathbf{x}}\le {\mathbf{xmax}}$.

None.

np1 la

Output Parameters

1:     result – double scalar
The value of the polynomial p(x)$p\left(\stackrel{-}{x}\right)$.
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$
 On entry, np1 < 1$\mathit{np1}<1$, or ia1 < 1${\mathbf{ia1}}<1$, or la ≤ (np1 − 1) × ia1$\mathit{la}\le \left(\mathit{np1}-1\right)×{\mathbf{ia1}}$, or ${\mathbf{xmin}}\ge {\mathbf{xmax}}$.
ifail = 2${\mathbf{ifail}}=2$
x does not satisfy the restriction ${\mathbf{xmin}}\le {\mathbf{x}}\le {\mathbf{xmax}}$.

Accuracy

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

Example

```function nag_fit_1dcheb_eval2_example
n = int64(6);
xmin = -0.5;
xmax = 2.5;
a = [2.53213;
1.13032;
0.2715;
0.04434;
0.00547;
0.00054;
4e-05];
ia1 = int64(1);
x = -0.5;
[result, ifail] = nag_fit_1dcheb_eval2(n, xmin, xmax, a, ia1, x)
```
```

result =

0.3679

ifail =

0

```
```function e02ak_example
n = int64(6);
xmin = -0.5;
xmax = 2.5;
a = [2.53213;
1.13032;
0.2715;
0.04434;
0.00547;
0.00054;
4e-05];
ia1 = int64(1);
x = -0.5;
[result, ifail] = e02ak(n, xmin, xmax, a, ia1, x)
```
```

result =

0.3679

ifail =

0

```