c06 Chapter Contents
c06 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_sum_cheby_series (c06dcc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_sum_cheby_series (const double x[], Integer lx, double xmin, double xmax, const double c[], Integer n, Nag_Series s, double res[], NagError *fail)

## 3  Description

nag_sum_cheby_series (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(\stackrel{-}{x}\right)$ ${\mathbf{s}}=\mathrm{Nag_SeriesEven}$: $0.5{c}_{1}+\sum _{\mathit{j}=2}^{n}{c}_{j}{T}_{2j-2}\left(\stackrel{-}{x}\right)$ ${\mathbf{s}}=\mathrm{Nag_SeriesOdd}$: $\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_1d_cheb_interp (e01aec) (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_ps_lin_solve (d02uec).

## 4  References

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

## 5  Arguments

1:    $\mathbf{x}\left[{\mathbf{lx}}\right]$const doubleInput
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}$IntegerInput
On entry: the number of evaluation points in $X$.
Constraint: ${\mathbf{lx}}\ge 1$.
3:    $\mathbf{xmin}$doubleInput
4:    $\mathbf{xmax}$doubleInput
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 $\stackrel{-}{x}$, where
 $x- = 2x-xmax+xmin xmax-xmin .$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
5:    $\mathbf{c}\left[{\mathbf{n}}\right]$const doubleInput
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}$IntegerInput
On entry: $n$, the number of terms in the series.
Constraint: ${\mathbf{n}}\ge 1$.
7:    $\mathbf{s}$Nag_SeriesInput
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]$doubleOutput
On exit: the Chebyshev series evaluated at the set of points $X$.
9:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction 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 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction 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$.

## 7  Accuracy

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

## 8  Parallelism and Performance

Not applicable.

The time taken increases with $n$.

## 10  Example

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

### 10.1  Program Text

Program Text (c06dcce.c)

### 10.2  Program Data

Program Data (c06dcce.d)

### 10.3  Program Results

Program Results (c06dcce.r)