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$X$, the sum of a Chebyshev series of one of three forms according to the value of the parameter s:
 s = 1${\mathbf{s}}=1$: 0.5c1 + ∑ j = 2n cj Tj − 1 (x) $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{j-1}\left(\stackrel{-}{x}\right)$ s = 2${\mathbf{s}}=2$: 0.5c1 + ∑ j = 2n cj T2j − 2 (x) $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{2j-2}\left(\stackrel{-}{x}\right)$ s = 3${\mathbf{s}}=3$: ∑ j = 1n cj T2j − 1 (x) $\sum _{\mathit{j}=1}^{n}{c}_{j}{T}_{2j-1}\left(\stackrel{-}{x}\right)$
where x$\stackrel{-}{x}$ lies in the range 1.0x1.0$-1.0\le \stackrel{-}{x}\le 1.0$. Here Tr(x)${T}_{r}\left(x\right)$ is the Chebyshev polynomial of order r$r$ in x$\stackrel{-}{x}$, defined by cos(ry)$\mathrm{cos}\left(ry\right)$ where cosy = x$\mathrm{cos}y=\stackrel{-}{x}$
It is assumed that the independent variable x$\stackrel{-}{x}$ in the interval [1.0, + 1.0]$\left[-1.0,+1.0\right]$ was obtained from your original variable xX$x\in X$, a set of real numbers 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 method used is based upon a three-term recurrence relation; for details see Clenshaw (1962).
The coefficients cj${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:     x(lx) – double array
lx, the dimension of the array, must satisfy the constraint lx1${\mathbf{lx}}\ge 1$.
xX$x\in X$, the set of arguments of the series.
Constraint: xminx(i)xmax${\mathbf{xmin}}\le {\mathbf{x}}\left(\mathit{i}\right)\le {\mathbf{xmax}}$, for i = 1,2,,lx$\mathit{i}=1,2,\dots ,{\mathbf{lx}}$.
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:     c(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
c(j)${\mathbf{c}}\left(\mathit{j}\right)$ must contain the coefficient cj${c}_{\mathit{j}}$ of the Chebyshev series, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
5:     s – int64int32nag_int scalar
Determines the series (see Section [Description]).
s = 1${\mathbf{s}}=1$
The series is general.
s = 2${\mathbf{s}}=2$
The series is even.
s = 3${\mathbf{s}}=3$
The series is odd.
Constraint: s = 1${\mathbf{s}}=1$, 2$2$ or 3$3$.

### Optional Input Parameters

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

None.

### Output Parameters

1:     res(lx) – double array
The Chebyshev series evaluated at the set of points X$X$.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

ifail = 1${\mathbf{ifail}}=1$
Constraint: lx1${\mathbf{lx}}\ge 1$.
ifail = 2${\mathbf{ifail}}=2$
Constraint: n1${\mathbf{n}}\ge 1$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: s = 1${\mathbf{s}}=1$, 2$2$ or 3$3$.
ifail = 4${\mathbf{ifail}}=4$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
ifail = 5${\mathbf{ifail}}=5$
Constraint: xminx(i)xmax${\mathbf{xmin}}\le {\mathbf{x}}\left(i\right)\le {\mathbf{xmax}}$, for all i$i$.

## Accuracy

There may be a loss of significant figures due to cancellation between terms. However, provided that n$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$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

```function nag_sum_chebyshev_example
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] = nag_sum_chebyshev(x, xmin, xmax, c, s);
fprintf('\nSums: \n');
disp(res);
```
```

Sums:
0.5000
2.2500
-0.0180

```
```function c06dc_example
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);
```
```

Sums:
0.5000
2.2500
-0.0180

```