# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine c06dcf ( x, lx, xmin, xmax, c, n, s, res,
 Integer, Intent (In) :: lx, n, s Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(lx), xmin, xmax, c(n) Real (Kind=nag_wp), Intent (Out) :: res(lx)
#include <nagmk26.h>
 void c06dcf_ (const double x[], const Integer *lx, const double *xmin, const double *xmax, const double c[], const Integer *n, const Integer *s, double res[], Integer *ifail)

## 3Description

c06dcf 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 routines, for example they may be those returned by the interpolation routine e01aef (in vector a), by a least squares fitting routine in Chapter E02, or as the solution of a boundary value problem by d02jaf, d02jbf or d02uef.
Clenshaw C W (1962) Chebyshev Series for Mathematical Functions Mathematical tables HMSO

## 5Arguments

1:     $\mathbf{x}\left({\mathbf{lx}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: $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:     $\mathbf{lx}$ – IntegerInput
On entry: the number of evaluation points in $X$.
Constraint: ${\mathbf{lx}}\ge 1$.
3:     $\mathbf{xmin}$ – Real (Kind=nag_wp)Input
4:     $\mathbf{xmax}$ – Real (Kind=nag_wp)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 $\stackrel{-}{x}$, where
 $x- = 2x-xmax+xmin xmax-xmin .$
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
5:     $\mathbf{c}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{c}}\left(\mathit{j}\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}$ – IntegerInput
On entry: determines the series (see Section 3).
${\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$.
8:     $\mathbf{res}\left({\mathbf{lx}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the Chebyshev series evaluated at the set of points $X$.
9:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value  is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value  is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{lx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lx}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{s}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{s}}=1$, $2$ or $3$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$ and ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
${\mathbf{ifail}}=5$
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$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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

## 8Parallelism and Performance

c06dcf is not threaded in any implementation.

The time taken increases with $n$.
c06dcf has been prepared in the present form to complement a number of integral equation solving routines which use Chebyshev series methods, e.g., d05aaf and d05abf.

## 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 (c06dcfe.f90)

### 10.2Program Data

Program Data (c06dcfe.d)

### 10.3Program Results

Program Results (c06dcfe.r)