# NAG CL Interfacee02ahc (dim1_​cheb_​deriv)

## 1Purpose

e02ahc determines the coefficients in the Chebyshev series representation of the derivative of a polynomial given in Chebyshev series form.

## 2Specification

 #include
 void e02ahc (Integer n, double xmin, double xmax, const double a[], Integer ia1, double *patm1, double adif[], Integer iadif1, NagError *fail)
The function may be called by the names: e02ahc, nag_fit_dim1_cheb_deriv or nag_1d_cheb_deriv.

## 3Description

e02ahc forms the polynomial which is the derivative of a given polynomial. Both the original polynomial and its derivative are represented in Chebyshev series form. Given the coefficients ${a}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$, of a polynomial $p\left(x\right)$ of degree $n$, where
 $px=12a0+a1T1x¯+⋯+anTnx¯$
the function returns the coefficients ${\overline{a}}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n-1$, of the polynomial $q\left(x\right)$ of degree $n-1$, where
 $qx=dpx dx =12a¯0+a¯1T1x¯+⋯+a¯n-1Tn-1x¯.$
Here ${T}_{j}\left(\overline{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\overline{x}$. It is assumed that the normalized variable $\overline{x}$ in the interval $\left[-1,+1\right]$ was obtained from your original variable $x$ in the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$ by the linear transformation
 $x¯=2x-xmax+xmin xmax-xmin$
and that you require the derivative to be with respect to the variable $x$. If the derivative with respect to $\overline{x}$ is required, set ${x}_{\mathrm{max}}=1$ and ${x}_{\mathrm{min}}=-1$.
Values of the derivative can subsequently be computed, from the coefficients obtained, by using e02akc.
The method employed is that of Chebyshev series (see Chapter 8 of Modern Computing Methods (1961)), modified to obtain the derivative with respect to $x$. Initially setting ${\overline{a}}_{n+1}={\overline{a}}_{n}=0$, the function forms successively
 $a¯i-1=a¯i+1+2xmax-xmin 2iai, i=n,n-1,…,1.$
Modern Computing Methods (1961) Chebyshev-series NPL Notes on Applied Science 16 (2nd Edition) HMSO

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the degree of the given polynomial $p\left(x\right)$.
Constraint: ${\mathbf{n}}\ge 0$.
2: $\mathbf{xmin}$double Input
3: $\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{xmax}}>{\mathbf{xmin}}$.
4: $\mathbf{a}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array a must be at least $\left(1+\left(1-1\right)×{\mathbf{ia1}},1+{\mathbf{n}}×{\mathbf{ia1}}\right)$.
On entry: the Chebyshev coefficients of the polynomial $p\left(x\right)$. Specifically, element $\mathit{i}×{\mathbf{ia1}}$ of a must contain the coefficient ${a}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$. Only these $n+1$ elements will be accessed.
5: $\mathbf{ia1}$Integer Input
On entry: the index increment of a. Most frequently the Chebyshev coefficients are stored in adjacent elements of a, and ia1 must be set to $1$. However, if for example, they are stored in ${\mathbf{a}}\left[0\right],{\mathbf{a}}\left[3\right],{\mathbf{a}}\left[6\right],\dots \text{}$, the value of ia1 must be $3$. See also Section 9.
Constraint: ${\mathbf{ia1}}\ge 1$.
6: $\mathbf{patm1}$double * Output
On exit: the value of $p\left({x}_{\mathrm{min}}\right)$. If this value is passed to the integration function e02ajc with the coefficients of $q\left(x\right)$, the original polynomial $p\left(x\right)$ is recovered, including its constant coefficient.
7: $\mathbf{adif}\left[\mathit{dim}\right]$double Output
Note: the dimension, dim, of the array adif must be at least $\left(1+\left(1-1\right)×{\mathbf{iadif1}},1+{\mathbf{n}}×{\mathbf{iadif1}}\right)$.
On exit: the Chebyshev coefficients of the derived polynomial $q\left(x\right)$. (The differentiation is with respect to the variable $x$.) Specifically, element $\mathit{i}×{\mathbf{iadif1}}$ of adif contains the coefficient ${\overline{a}}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n-1$. Additionally, element $n×{\mathbf{iadif1}}$ is set to zero.
8: $\mathbf{iadif1}$Integer Input
On entry: the index increment of adif. Most frequently the Chebyshev coefficients are required in adjacent elements of adif, and iadif1 must be set to $1$. However, if, for example, they are to be stored in ${\mathbf{adif}}\left[0\right],{\mathbf{adif}}\left[3\right],{\mathbf{adif}}\left[6\right],\dots \text{}$, the value of iadif1 must be $3$. See Section 9.
Constraint: ${\mathbf{iadif1}}\ge 1$.
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.
NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{ia1}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ia1}}\ge 1$.
On entry, ${\mathbf{iadif1}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{iadif1}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
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{xmax}}>{\mathbf{xmin}}$.

## 7Accuracy

There is always a loss of precision in numerical differentiation, in this case associated with the multiplication by $2i$ in the formula quoted in Section 3.

## 8Parallelism and Performance

e02ahc is not threaded in any implementation.

## 9Further Comments

The time taken is approximately proportional to $n+1$.
The increments ia1, iadif1 are included as arguments to give a degree of flexibility which, for example, allows a polynomial in two variables to be differentiated with respect to either variable without rearranging the coefficients.

## 10Example

Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval $\left[-0.5,2.5\right]$. The following program evaluates the first and second derivatives of this polynomial at $4$ equally spaced points over the interval. (For the purposes of this example, xmin, xmax and the Chebyshev coefficients are simply supplied. Normally a program would first read in or generate data and compute the fitted polynomial.)

### 10.1Program Text

Program Text (e02ahce.c)

None.

### 10.3Program Results

Program Results (e02ahce.r)