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_2dcheb_eval (e02cb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_fit_2dcheb_eval (e02cb) evaluates a bivariate polynomial from the rectangular array of coefficients in its double Chebyshev series representation.

Syntax

[ff, ifail] = e02cb(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a, 'mlast', mlast)
[ff, ifail] = nag_fit_2dcheb_eval(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a, 'mlast', mlast)

Description

This function evaluates a bivariate polynomial (represented in double Chebyshev form) of degree k in one variable, x-, and degree l in the other, y-. The range of both variables is -1 to +1. However, these normalized variables will usually have been derived (as when the polynomial has been computed by nag_fit_2dcheb_lines (e02ca), for example) from your original variables x and y by the transformations
x-=2x-xmax+xmin xmax-xmin   and  y-=2y-ymax+ymin ymax-ymin .  
(Here xmin and xmax are the ends of the range of x which has been transformed to the range -1 to +1 of x-. ymin and ymax are correspondingly for y. See Further Comments). For this reason, the function has been designed to accept values of x and y rather than x- and y-, and so requires values of xmin, etc. to be supplied by you. In fact, for the sake of efficiency in appropriate cases, the function evaluates the polynomial for a sequence of values of x, all associated with the same value of y.
The double Chebyshev series can be written as
i=0kj=0laijTix-Tjy-,  
where Tix- is the Chebyshev polynomial of the first kind of degree i and argument x-, and Tjy- is similarly defined. However the standard convention, followed in this function, is that coefficients in the above expression which have either i or j zero are written 12aij, instead of simply aij, and the coefficient with both i and j zero is written 14a0,0.
The function first forms ci=j=0laijTjy-, with ai,0 replaced by 12ai,0, for each of i=0,1,,k. The value of the double series is then obtained for each value of x, by summing ci×Tix-, with c0 replaced by 12c0, over i=0,1,,k. The Clenshaw three term recurrence (see Clenshaw (1955)) with modifications due to Reinsch and Gentleman (1969) is used to form the sums.

References

Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
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:     mfirst int64int32nag_int scalar
The index of the first and last x value in the array x at which the evaluation is required respectively (see Further Comments).
Constraint: mlastmfirst.
2:     k int64int32nag_int scalar
3:     l int64int32nag_int scalar
The degree k of x and l of y, respectively, in the polynomial.
Constraint: k0 and l0.
4:     xmlast – double array
xi, for i=mfirst,,mlast, must contain the x values at which the evaluation is required.
Constraint: xminxixmax, for all i.
5:     xmin – double scalar
6:     xmax – double scalar
The lower and upper ends, xmin and xmax, of the range of the variable x (see Description).
The values of xmin and xmax may depend on the value of y (e.g., when the polynomial has been derived using nag_fit_2dcheb_lines (e02ca)).
Constraint: xmax>xmin.
7:     y – double scalar
The value of the y coordinate of all the points at which the evaluation is required.
Constraint: yminyymax.
8:     ymin – double scalar
9:     ymax – double scalar
The lower and upper ends, ymin and ymax, of the range of the variable y (see Description).
Constraint: ymax>ymin.
10:   ana – double array
na, the dimension of the array, must satisfy the constraint nak+1×l+1, the number of coefficients in a polynomial of the specified degree.
The Chebyshev coefficients of the polynomial. The coefficient aij defined according to the standard convention (see Description) must be in ai×l+1+j+1.

Optional Input Parameters

1:     mlast int64int32nag_int scalar
Default: For mlast, the dimension of the array x.
The index of the first and last x value in the array x at which the evaluation is required respectively (see Further Comments).
Constraint: mlastmfirst.

Output Parameters

1:     ffmlast – double array
ffi gives the value of the polynomial at the point xi,y, for i=mfirst,,mlast.
2:     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,mfirst>mlast,
ork<0,
orl<0,
orna<k+1×l+1,
ornwork<k+1.
   ifail=2
On entry,yminymax,
ory<ymin,
ory>ymax.
   ifail=3
On entry,xminxmax,
orxi<xmin, or xi>xmax, for some i=mfirst,mfirst+1,,mlast.
   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

The method is numerically stable in the sense that the computed values of the polynomial are exact for a set of coefficients which differ from those supplied by only a modest multiple of machine precision.

Further Comments

The time taken is approximately proportional to k+1×m+l+1, where m=mlast-mfirst+1, the number of points at which the evaluation is required.
This function is suitable for evaluating the polynomial surface fits produced by the function nag_fit_2dcheb_lines (e02ca), which provides the double array a in the required form. For this use, the values of ymin and ymax supplied to the present function must be the same as those supplied to nag_fit_2dcheb_lines (e02ca). The same applies to xmin and xmax if they are independent of y. If they vary with y, their values must be consistent with those supplied to nag_fit_2dcheb_lines (e02ca) (see Further Comments in nag_fit_2dcheb_lines (e02ca)).
The arguments mfirst and mlast are intended to permit the selection of a segment of the array x which is to be associated with a particular value of y, when, for example, other segments of x are associated with other values of y. Such a case arises when, after using nag_fit_2dcheb_lines (e02ca) to fit a set of data, you wish to evaluate the resulting polynomial at all the data values. In this case, if the arguments x, y, mfirst and mlast of the present function are set respectively (in terms of arguments of nag_fit_2dcheb_lines (e02ca)) to x, yS, 1+i=1 s-1mi and i=1smi, the function will compute values of the polynomial surface at all data points which have yS as their y coordinate (from which values the residuals of the fit may be derived).

Example

This example reads data in the following order, using the notation of the argument list above:
Nkl ai, for ​i=1,2,,k+1×l+1 yminymax yiMixminixmaxiX1iXMi, for ​i=1,2,,N.  
For each line y=yi the polynomial is evaluated at Mi equispaced points between X1i and XMi inclusive.
function e02cb_example


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


% domain
dx   = 4/19;
x    = [0.5:dx:4.5];
y    = [0:dx:4];
xmin = 0.1; xmax = 4.5;
ymin = 0;   ymax = 4;

% Fit characteristics and coefficients
k = int64(3);
l = int64(2);
a = [15.3482   5.15073  -2.20140   1.14719  -0.64419   0.30464 ...
     -0.4901  -0.00314  -6.69912   0.00153   3.00033  -0.00022];

% Evaluations on mesh
mfirst = int64(1);
mlast  = int64(20);

% Evaluate fit 
for i = 1:mlast
  [fit(:,i), ifail] = e02cb( ...
                             mfirst, k, l, x, xmin, xmax, y(i), ...
                             ymin, ymax, a, 'mlast', mlast);
  sol = [x; fit(:,i)'];
end

fprintf('\nThe bivariate polynomial fit values for y = %5.1f are:\n',y(mlast));
sol = [x; fit(:,mlast)'];
fprintf('      x       p(x,y=4)\n', sol);
fprintf('%11.4f%11.4f\n', sol);

fig1 = figure;
meshc(y,x,fit);
title('Least-squares bi-variate polynomial fit');
xlabel('x');
ylabel('y');
zlabel('p(x,y)');


e02cb example results


The bivariate polynomial fit values for y =   4.0 are:
      x       p(x,y=4)
     0.5000     3.5575
     0.7105     6.8145
     0.9211     9.3405
     1.1316    11.1986
     1.3421    12.4520
     1.5526    13.1637
     1.7632    13.3970
     1.9737    13.2148
     2.1842    12.6803
     2.3947    11.8566
     2.6053    10.8069
     2.8158     9.5942
     3.0263     8.2816
     3.2368     6.9323
     3.4474     5.6094
     3.6579     4.3760
     3.8684     3.2951
     4.0789     2.4300
     4.2895     1.8437
     4.5000     1.5993
e02cb_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