# NAG CL Interfacec06dcc (chebyshev)

## 1Purpose

c06dcc evaluates a polynomial from its Chebyshev series representation at a set of points.

## 2Specification

 #include
 void c06dcc (const double x[], Integer lx, double xmin, double xmax, const double c[], Integer n, Nag_Series s, double res[], NagError *fail)
The function may be called by the names: c06dcc, nag_sum_chebyshev or nag_sum_cheby_series.

## 3Description

c06dcc 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}}=\mathrm{Nag_SeriesGeneral}$: $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{j-1}\left(\overline{x}\right)$ ${\mathbf{s}}=\mathrm{Nag_SeriesEven}$: $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{2j-2}\left(\overline{x}\right)$ ${\mathbf{s}}=\mathrm{Nag_SeriesOdd}$: $\sum _{\mathit{j}=1}^{n}{c}_{j}{T}_{2j-1}\left(\overline{x}\right)$
where $\overline{x}$ lies in the range $-1.0\le \overline{x}\le 1.0$. Here ${T}_{r}\left(x\right)$ is the Chebyshev polynomial of order $r$ in $\overline{x}$, defined by $\mathrm{cos}\left(ry\right)$ where $\mathrm{cos}y=\overline{x}$.
It is assumed that the independent variable $\overline{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 e01aec (in vector a), by a least squares fitting function in Chapter E02, or as the solution of a boundary value problem by d02uec.

## 4References

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

## 5Arguments

1: $\mathbf{x}\left[{\mathbf{lx}}\right]$const double Input
On entry: $x\in X$, the set of arguments of the series.
Constraint: ${\mathbf{xmin}}\le {\mathbf{x}}\left[\mathit{i}-1\right]\le {\mathbf{xmax}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lx}}$.
2: $\mathbf{lx}$Integer Input
On entry: the number of evaluation points in $X$.
Constraint: ${\mathbf{lx}}\ge 1$.
3: $\mathbf{xmin}$double Input
4: $\mathbf{xmax}$double 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}}$.
5: $\mathbf{c}\left[{\mathbf{n}}\right]$const double Input
On entry: ${\mathbf{c}}\left[\mathit{j}-1\right]$ must contain the coefficient ${c}_{\mathit{j}}$ of the Chebyshev series, for $\mathit{j}=1,2,\dots ,n$.
6: $\mathbf{n}$Integer Input
On entry: $n$, the number of terms in the series.
Constraint: ${\mathbf{n}}\ge 1$.
7: $\mathbf{s}$Nag_Series Input
On entry: determines the series (see Section 3).
${\mathbf{s}}=\mathrm{Nag_SeriesGeneral}$
The series is general.
${\mathbf{s}}=\mathrm{Nag_SeriesEven}$
The series is even.
${\mathbf{s}}=\mathrm{Nag_SeriesOdd}$
The series is odd.
Constraint: ${\mathbf{s}}=\mathrm{Nag_SeriesGeneral}$, $\mathrm{Nag_SeriesEven}$ or $\mathrm{Nag_SeriesOdd}$.
8: $\mathbf{res}\left[{\mathbf{lx}}\right]$double Output
On exit: the Chebyshev series evaluated at the set of points $X$.
9: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{lx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lx}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_2
On entry, ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$ and ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
NE_REAL_3
On entry, element ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$ and ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmin}}\le {\mathbf{x}}\left[i\right]\le {\mathbf{xmax}}$, for all $i$.

## 7Accuracy

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

## 8Parallelism and Performance

c06dcc is not threaded in any implementation.

The time taken increases with $n$.

## 10Example

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

### 10.1Program Text

Program Text (c06dcce.c)

### 10.2Program Data

Program Data (c06dcce.d)

### 10.3Program Results

Program Results (c06dcce.r)