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_glp (e02af)

Purpose

nag_fit_1dcheb_glp (e02af) computes the coefficients of a polynomial, in its Chebyshev series form, which interpolates (passes exactly through) data at a special set of points. Least squares polynomial approximations can also be obtained.

Syntax

[a, ifail] = e02af(f, 'nplus1', nplus1)
[a, ifail] = nag_fit_1dcheb_glp(f, 'nplus1', nplus1)

Description

nag_fit_1dcheb_glp (e02af) computes the coefficients ajaj, for j = 1,2,,n + 1j=1,2,,n+1, in the Chebyshev series
(1/2)a1T0(x) + a2T1(x) + a3T2(x) + + an + 1Tn(x),
12a1T0(x-)+a2T1(x-)+a3T2(x-)++an+1Tn(x-),
which interpolates the data frfr at the points
xr = cos((r1)π / n) ,  r = 1,2,,n + 1.
x-r=cos((r-1)π/n) ,  r=1,2,,n+1.
Here Tj(x)Tj(x-) denotes the Chebyshev polynomial of the first kind of degree jj with argument xx-. The use of these points minimizes the risk of unwanted fluctuations in the polynomial and is recommended when the data abscissae can be chosen by you, e.g., when the data is given as a graph. For further advantages of this choice of points, see Clenshaw (1962).
In terms of your original variables, xx say, the values of xx at which the data frfr are to be provided are
xr = (1/2)(xmaxxmin)cos(π(r1) / n) + (1/2)(xmax + xmin),  r = 1,2,,n + 1
xr=12(xmax-xmin)cos(π(r-1)/n)+12(xmax+xmin),  r=1,2,,n+1
where xmaxxmax and xminxmin are respectively the upper and lower ends of the range of xx over which you wish to interpolate.
Truncation of the resulting series after the term involving ai + 1ai+1, say, yields a least squares approximation to the data. This approximation, p(x)p(x-), say, is the polynomial of degree ii which minimizes
(1/2)ε12 + ε22 + ε32 + + εn2 + (1/2)εn + 12,
12ε12+ε22+ε32++εn2+12εn+12,
where the residual εr = p(xr)frεr=p(x-r)-fr, for r = 1,2,,n + 1r=1,2,,n+1.
The method employed is based on the application of the three-term recurrence relation due to Clenshaw (1955) for the evaluation of the defining expression for the Chebyshev coefficients (see, for example, Clenshaw (1962)). The modifications to this recurrence relation suggested by Reinsch and Gentleman (see Gentleman (1969)) are used to give greater numerical stability.
For further details of the algorithm and its use see Cox (1974) and Cox and Hayes (1973).
Subsequent evaluation of the computed polynomial, perhaps truncated after an appropriate number of terms, should be carried out using nag_fit_1dcheb_eval (e02ae).

References

Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
Clenshaw C W (1962) Chebyshev Series for Mathematical Functions Mathematical tables HMSO
Cox M G (1974) A data-fitting package for the non-specialist user Software for Numerical Mathematics (ed D J Evans) Academic Press
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
Gentleman W M (1969) An error analysis of Goertzel's (Watt's) method for computing Fourier coefficients Comput. J. 12 160–165

Parameters

Compulsory Input Parameters

1:     f(nplus1) – double array
nplus1, the dimension of the array, must satisfy the constraint nplus12nplus12.
For r = 1,2,,n + 1r=1,2,,n+1, f(r)fr must contain frfr the value of the dependent variable (ordinate) corresponding to the value
xr = cos(π(r1) / n)
x-r=cos(π(r-1)/n)
of the independent variable (abscissa) xx-, or equivalently to the value
x(r) = (1/2)(xmaxxmin)cos(π(r1) / n) + (1/2)(xmax + xmin)
x(r)=12(xmax-xmin)cos(π(r-1)/n)+12(xmax+xmin)
of your original variable xx. Here xmaxxmax and xminxmin are respectively the upper and lower ends of the range over which you wish to interpolate.

Optional Input Parameters

1:     nplus1 – int64int32nag_int scalar
Default: The dimension of the array f.
The number n + 1n+1 of data points (one greater than the degree nn of the interpolating polynomial).
Constraint: nplus12nplus12.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     a(nplus1) – double array
a(j)aj is the coefficient ajaj in the interpolating polynomial, for j = 1,2,,n + 1j=1,2,,n+1.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,nplus1 < 2nplus1<2.

Accuracy

The rounding errors committed are such that the computed coefficients are exact for a slightly perturbed set of ordinates fr + δfrfr+δfr. The ratio of the sum of the absolute values of the δfrδfr to the sum of the absolute values of the frfr is less than a small multiple of (n + 1)ε(n+1)ε, where εε is the machine precision.

Further Comments

The time taken is approximately proportional to (n + 1)2 + 30 (n+1) 2+30.
For choice of degree when using the function for least squares approximation, see Section [Polynomial Curves] in the E02 Chapter Introduction.

Example

function nag_fit_1dcheb_glp_example
f = [2.7182;
     2.5884;
     2.2456;
     1.7999;
     1.362;
     1;
     0.7341;
     0.5555;
     0.4452;
     0.3863;
     0.3678];
[a, ifail] = nag_fit_1dcheb_glp(f)
 

a =

    2.5320
    1.1303
    0.2715
    0.0443
    0.0055
    0.0005
    0.0000
   -0.0000
   -0.0000
    0.0000
   -0.0000


ifail =

                    0


function e02af_example
f = [2.7182;
     2.5884;
     2.2456;
     1.7999;
     1.362;
     1;
     0.7341;
     0.5555;
     0.4452;
     0.3863;
     0.3678];
[a, ifail] = e02af(f)
 

a =

    2.5320
    1.1303
    0.2715
    0.0443
    0.0055
    0.0005
    0.0000
   -0.0000
   -0.0000
    0.0000
   -0.0000


ifail =

                    0



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–2013