NAG C Library Function Document

nag_1d_cheb_deriv (e02ahc)


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


#include <nag.h>
#include <nage02.h>
void  nag_1d_cheb_deriv (Integer n, double xmin, double xmax, const double a[], Integer ia1, double *patm1, double adif[], Integer iadif1, NagError *fail)


nag_1d_cheb_deriv (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 ai, for i=0,1,,n, of a polynomial px of degree n, where
the function returns the coefficients a-i, for i=0,1,,n-1, of the polynomial qx of degree n-1, where
qx=dpx dx =12a-0+a-1T1x-++a-n-1Tn-1x-.  
Here Tjx- denotes the Chebyshev polynomial of the first kind of degree j with argument x-. It is assumed that the normalized variable x- in the interval -1,+1 was obtained from your original variable x in the interval xmin,xmax 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 x- is required, set xmax=1 and xmin=-1.
Values of the derivative can subsequently be computed, from the coefficients obtained, by using nag_1d_cheb_eval2 (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 a-n+1=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


1:     n IntegerInput
On entry: n, the degree of the given polynomial px.
Constraint: n0.
2:     xmin doubleInput
3:     xmax doubleInput
On entry: the lower and upper end points respectively of the interval xmin,xmax. The Chebyshev series representation is in terms of the normalized variable x-, where
x-=2x-xmax+xmin xmax-xmin .  
Constraint: xmax>xmin.
4:     a[dim] const doubleInput
Note: the dimension, dim, of the array a must be at least 1+n+1-1×ia1.
On entry: the Chebyshev coefficients of the polynomial px. Specifically, element i×ia1 of a must contain the coefficient ai, for i=0,1,,n. Only these n+1 elements will be accessed.
5:     ia1 IntegerInput
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 a[0],a[3],a[6],, the value of ia1 must be 3. See also Section 9.
Constraint: ia11.
6:     patm1 double *Output
On exit: the value of pxmin. If this value is passed to the integration function nag_1d_cheb_intg (e02ajc) with the coefficients of qx, the original polynomial px is recovered, including its constant coefficient.
7:     adif[dim] doubleOutput
Note: the dimension, dim, of the array adif must be at least 1+n+1-1×iadif1.
On exit: the Chebyshev coefficients of the derived polynomial qx. (The differentiation is with respect to the variable x.) Specifically, element i×iadif1 of adif contains the coefficient a-i, for i=0,1,,n-1. Additionally, element n×iadif1 is set to zero.
8:     iadif1 IntegerInput
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 adif[0],adif[3],adif[6],, the value of iadif1 must be 3. See Section 9.
Constraint: iadif11.
9:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, ia1=value.
Constraint: ia11.
On entry, iadif1=value.
Constraint: iadif11.
On entry, n+1=value.
Constraint: n+11.
On entry, n=value.
Constraint: n0.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
On entry, xmax=value and xmin=value.
Constraint: xmax>xmin.


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.

Parallelism and Performance

nag_1d_cheb_deriv (e02ahc) is not threaded in any implementation.

Further 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.


Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval -0.5,2.5. 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.)

Program Text

Program Text (e02ahce.c)

Program Data


Program Results

Program Results (e02ahce.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 0.5 1 1.5 2 2.5 3 −0.5 0 0.5 1 1.5 2 2.5 P(x), P'(x), P''(x) x Example Program Evaluation of Chebyshev Polynomial and its Derivatives P(x) P'(x) P''(x) gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3