hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_fit_1dcheb_deriv (e02ah)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

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

Syntax

[patm1, adif, ifail] = e02ah(n, xmin, xmax, a, ia1, iadif1)
[patm1, adif, ifail] = nag_fit_1dcheb_deriv(n, xmin, xmax, a, ia1, iadif1)

Description

nag_fit_1dcheb_deriv (e02ah) 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
px=12a0+a1T1x-++anTnx-  
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_fit_1dcheb_eval2 (e02ak).
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.  

References

Modern Computing Methods (1961) Chebyshev-series NPL Notes on Applied Science 16 (2nd Edition) HMSO

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the degree of the given polynomial px.
Constraint: n0.
2:     xmin – double scalar
3:     xmax – double scalar
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:     ala – double array
la, the dimension of the array, must satisfy the constraint la1+np1-1×ia1.
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.
Unchanged on exit, but see adif, below.
5:     ia1 int64int32nag_int scalar
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 a1,a4,a7,, then the value of ia1 must be 3. See also Further Comments.
Constraint: ia11.
6:     iadif1 int64int32nag_int scalar
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 adif1,adif4,adif7,, then the value of iadif1 must be 3. See Further Comments.
Constraint: iadif11.

Optional Input Parameters

None.

Output Parameters

1:     patm1 – double scalar
The value of pxmin. If this value is passed to the integration function nag_fit_1dcheb_integ (e02aj) with the coefficients of qx, then the original polynomial px is recovered, including its constant coefficient.
2:     adifladif – double array
ladif=1+np1-1 ×iadif1.
The Chebyshev coefficients of the derived polynomial qx. (The differentiation is with respect to the variable x.) Specifically, element i×iadif1+1 of adif contains the coefficient a-i, for i=0,1,,n-1. Additionally, element n×iadif1+1 is set to zero. A call of the function may have the array name adif the same as a, provided that note is taken of the order in which elements are overwritten, when choosing the starting elements and increments ia1 and iadif1, i.e., the coefficients a0,a1,,ai-1 must be intact after coefficient a-i is stored. In particular, it is possible to overwrite the ai completely by having ia1=iadif1, and the actual arrays for a and adif identical.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,np1<1,
orxmaxxmin,
oria1<1,
orlanp1-1×ia1,
oriadif1<1,
orladifnp1-1×iadif1.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

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.

Example

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.)
function e02ah_example


fprintf('e02ah example results\n\n');

xmin = -0.5; xmax = 2.5;
a = [2.53213  1.13032  0.2715  0.04434   0.00547   0.00054  4e-05];

n = int64(6);
ia1 = int64(1);
iadif1 = int64(1);

% Get first derivative
[patm1, adif, ifail] = e02ah( ...
                              n, xmin, xmax, a, ia1, iadif1);

% Get second derivative
[patm1, adif2, ifail] = e02ah( ...
                               n, xmin, xmax, adif, ia1, iadif1);

% Evaluate polynomial and derivatives from coefficients adif and adif2 at x
m = 21;
dx =  (xmax-xmin)/(m-1);
x = [xmin:dx:xmax];

for i = 1:m
  [fit0(i), ifail] = e02ak( ...
                             n, xmin, xmax, a, ia1, x(i));
  [fit1(i), ifail] = e02ak( ...
                             n-1, xmin, xmax, adif, iadif1, x(i));
  [fit2(i), ifail] = e02ak( ...
                             n-2, xmin, xmax, adif2, iadif1, x(i));
end

sol = [x; fit0; fit1; fit2];
fprintf('     x           p(x)         p''(x)        p''''(x)\n');
fprintf('%9.4f    %9.4f    %9.4f    %9.4f\n',sol(1:4,1:5:21));

fig1 = figure;
plot(x,fit0,x,fit1,x,fit2);
title('Evaluation of Chebyshev Polynomial and its Derivatives');
xlabel('x');
ylabel('p(x),p''(x),p''''(x)');
legend('p(x)', 'p''(x)', 'p''''(x)','Location','NorthWest');


e02ah example results

     x           p(x)         p'(x)        p''(x)
  -0.5000       0.3679       0.2453       0.1637
   0.2500       0.6065       0.4043       0.2696
   1.0000       1.0000       0.6667       0.4444
   1.7500       1.6487       1.0992       0.7329
   2.5000       2.7183       1.8119       1.2056
e02ah_fig1.png

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015