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_sum_chebyshev (c06dc)

## Purpose

nag_sum_chebyshev (c06dc) evaluates a polynomial from its Chebyshev series representation at a set of points.

## Syntax

[res, ifail] = c06dc(x, xmin, xmax, c, s, 'lx', lx, 'n', n)
[res, ifail] = nag_sum_chebyshev(x, xmin, xmax, c, s, 'lx', lx, 'n', n)

## Description

nag_sum_chebyshev (c06dc) evaluates, at each point in a given set $X$, the sum of a Chebyshev series of one of three forms according to the value of the parameter s:
 ${\mathbf{s}}=1$: $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{j-1}\left(\stackrel{-}{x}\right)$ ${\mathbf{s}}=2$: $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{2j-2}\left(\stackrel{-}{x}\right)$ ${\mathbf{s}}=3$: $\sum _{\mathit{j}=1}^{n}{c}_{j}{T}_{2j-1}\left(\stackrel{-}{x}\right)$
where $\stackrel{-}{x}$ lies in the range $-1.0\le \stackrel{-}{x}\le 1.0$. Here ${T}_{r}\left(x\right)$ is the Chebyshev polynomial of order $r$ in $\stackrel{-}{x}$, defined by $\mathrm{cos}\left(ry\right)$ where $\mathrm{cos}y=\stackrel{-}{x}$
It is assumed that the independent variable $\stackrel{-}{x}$ in the interval $\left[-1.0,+1.0\right]$ was obtained from your original variable $x\in X$, a set of real numbers in the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$, by the linear transformation
 $x- = 2x-xmax+xmin xmax-xmin .$
The method used is based upon a three-term recurrence relation; for details see Clenshaw (1962).
The coefficients ${c}_{j}$ are normally generated by other functions, for example they may be those returned by the interpolation function nag_interp_1d_cheb (e01ae) (in vector a), by a least squares fitting function in Chapter E02, or as the solution of a boundary value problem by nag_ode_bvp_coll_nth (d02ja), nag_ode_bvp_coll_sys (d02jb) or nag_ode_bvp_ps_lin_solve (d02ue).

## References

Clenshaw C W (1962) Chebyshev Series for Mathematical Functions Mathematical tables HMSO

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{lx}}\right)$ – double array
$x\in X$, the set of arguments of the series.
Constraint: ${\mathbf{xmin}}\le {\mathbf{x}}\left(\mathit{i}\right)\le {\mathbf{xmax}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lx}}$.
2:     $\mathrm{xmin}$ – double scalar
3:     $\mathrm{xmax}$ – double scalar
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:     $\mathrm{c}\left({\mathbf{n}}\right)$ – double array
${\mathbf{c}}\left(\mathit{j}\right)$ must contain the coefficient ${c}_{\mathit{j}}$ of the Chebyshev series, for $\mathit{j}=1,2,\dots ,n$.
5:     $\mathrm{s}$int64int32nag_int scalar
Determines the series (see Description).
${\mathbf{s}}=1$
The series is general.
${\mathbf{s}}=2$
The series is even.
${\mathbf{s}}=3$
The series is odd.
Constraint: ${\mathbf{s}}=1$, $2$ or $3$.

### Optional Input Parameters

1:     $\mathrm{lx}$int64int32nag_int scalar
Default: the dimension of the array x.
The number of evaluation points in $X$.
Constraint: ${\mathbf{lx}}\ge 1$.
2:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array c.
$n$, the number of terms in the series.
Constraint: ${\mathbf{n}}\ge 1$.

### Output Parameters

1:     $\mathrm{res}\left({\mathbf{lx}}\right)$ – double array
The Chebyshev series evaluated at the set of points $X$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{lx}}\ge 1$.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{s}}=1$, $2$ or $3$.
${\mathbf{ifail}}=4$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
${\mathbf{ifail}}=5$
Constraint: ${\mathbf{xmin}}\le {\mathbf{x}}\left(i\right)\le {\mathbf{xmax}}$, for all $i$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

There may be a loss of significant figures due to cancellation between terms. However, provided that $n$ is not too large, nag_sum_chebyshev (c06dc) yields results which differ little from the best attainable for the available machine precision.

The time taken increases with $n$.
nag_sum_chebyshev (c06dc) has been prepared in the present form to complement a number of integral equation solving functions which use Chebyshev series methods, e.g., nag_inteq_fredholm2_split (d05aa) and nag_inteq_fredholm2_smooth (d05ab).

## Example

This example evaluates
 $0.5+ T1x+ 0.5T2x+ 0.25T3x$
at the points $X=\left[0.5,1.0,-0.2\right]$.
```function c06dc_example

fprintf('c06dc example results\n\n');

x = [0.5, 1.0, -0.2];
xmin = -1;
xmax =  1;
s = int64(1);
c = [1.0, 1.0, 0.5, 0.25];

[res, ifail] = c06dc(x, xmin, xmax, c, s);
fprintf('\nSums: \n');
disp(res);

```
```c06dc example results

Sums:
0.5000
2.2500
-0.0180

```