3 Description

nag_2d_cheb_fit_lines (e02cac) determines a bivariate polynomial approximation of degree k in x and l in y to the set of data points xr,s,ys,fr,s, with weights wr,s, for s=1,2,…,n and r=1,2,…,ms. That is, the data points are on lines y=ys, but the x values may be different on each line. The values of k and l are prescribed by you (for guidance on their choice, see Section 9). The function is based on the method described in Sections 5 and 6 of Clenshaw and Hayes (1965).

The polynomial is represented in double Chebyshev series form with arguments x- and y-. The arguments lie in the range -1 to +1 and are related to the original variables x and y by the transformations

x-=2x-xmax+xminxmax-xmin and y-=2y-ymax+yminymax-ymin.

Here ymax and ymin are set by the function to, respectively, the largest and smallest value of ys, but xmax and xmin are functions of y prescribed by you (see Section 9). For this function, only their values xmaxs and xmins at each y=ys are required. For each s=1,2,…,n, xmaxs must not be less than the largest xr,s on the line y=ys, and, similarly, xmins must not be greater than the smallest xr,s.

The double Chebyshev series can be written as

∑i=0k∑j=0laijTix-Tjy-

where Tix- is the Chebyshev polynomial of the first kind of degree i with 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 as 12aij, instead of simply aij, and the coefficient with both i and j equal to zero is written as 14a0,0. The series with coefficients output by the function should be summed using this convention. nag_2d_cheb_eval (e02cbc) is available to compute values of the fitted function from these coefficients.

The function first obtains Chebyshev series coefficients cs,i, for i=0,1,…,k, of the weighted least squares polynomial curve fit of degree k in x- to the data on each line y=ys, for s=1,2,…,n, in turn, using an auxiliary function. The same function is then called k+1 times to fit cs,i, for s=1,2,…,n, by a polynomial of degree l in y-, for each i=0,1,…,k. The resulting coefficients are the required aij.

You can force the fit to contain a given polynomial factor. This allows for the surface fit to be constrained to have specified values and derivatives along the boundaries x=xmin, x=xmax, y=ymin and y=ymax or indeed along any lines x-= constant or y-= constant (see Section 8 of Clenshaw and Hayes (1965)).

On entry: y[s-1] must contain the y value of line y=ys, for s=1,2,…,n, on which data is given.

Constraint:
the ys values must be in strictly increasing order.

7:
f[dim] – const doubleInput

Note: the dimension, dim, of the array f
must be at least
∑s=1nm[s-1].

On entry: f, the data values of the dependent variable in the same sequence as the x values.

8:
w[dim] – const doubleInput

Note: the dimension, dim, of the array w
must be at least
∑s=1nm[s-1].

On entry: the weights to be assigned to the data points, in the same sequence as the x values. These weights should be calculated from estimates of the absolute accuracies of the fr, expressed as standard deviations, probable errors or some other measure which is of the same dimensions as fr. Specifically, each wr should be inversely proportional to the accuracy estimate of fr. Often weights all equal to unity will be satisfactory. If a particular weight is zero, the corresponding data point is omitted from the fit.

On exit: contains the Chebyshev coefficients of the fit. a[i×l+1+j-1] is the coefficient aij of Section 3 defined according to the standard convention. These coefficients are used by nag_2d_cheb_eval (e02cbc) to calculate values of the fitted function.

On entry: xmin[s-1] must contain xmins, the lower end of the range of x on the line y=ys, for s=1,2,…,n. It must not be greater than the lowest data value of x on the line. Each xmins is scaled to -1.0 in the fit. (See also Section 9.)

On entry: xmax[s-1] must contain xmaxs, the upper end of the range of x on the line y=ys, for s=1,2,…,n. It must not be less than the highest data value of x on the line. Each xmaxs is scaled to +1.0 in the fit. (See also Section 9.)

On entry: nux[i-1] must contain the coefficient of the Chebyshev polynomial of degree i-1 in x-, in the Chebyshev series representation of the polynomial factor in x- which you require the fit to contain, for i=1,2,…,inuxp1. These coefficients are defined according to the standard convention of Section 3.

Constraint:
nux[inuxp1-1] must be nonzero, unless inuxp1=1, in which case nux is ignored.

13:
inuxp1 – IntegerInput

On entry: INUX+1, where INUX is the degree of a polynomial factor in x- which you require the fit to contain. (See Section 3, last paragraph.)

On entry: nuy[i-1] must contain the coefficient of the Chebyshev polynomial of degree i-1 in y-, in the Chebyshev series representation of the polynomial factor which you require the fit to contain, for i=1,2,…,inuyp1. These coefficients are defined according to the standard convention of Section 3.

Constraint:
nuy[inuyp1-1] must be nonzero, unless inuyp1=1, in which case nuy is ignored.

15:
inuyp1 – IntegerInput

On entry: INUY+1, where INUY is the degree of a polynomial factor in y- which you require the fit to contain. (See Section 3, last paragraph.) If this option is not required, inuyp1 should be set equal to 1.

On entry, xmin[I-1] and xmax[I-1] do not span the data x values on y=y[I-1]: I=value, xmin[I-1]=value, xmax[I-1]=value and y[I-1]=value.

7 Accuracy

No error analysis for this method has been published. Practical experience with the method, however, is generally extremely satisfactory.

8 Parallelism and Performance

nag_2d_cheb_fit_lines (e02cac) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.

Please consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The time taken is approximately proportional to k×k×∑s=1nm[s-1]+n×l2.

The reason for allowing xmax and xmin (which are used to normalize the range of x) to vary with y is that unsatisfactory fits can result if the highest (or lowest) data values of the normalized x on each line y=ys are not approximately the same. (For an explanation of this phenomenon, see page 176 of Clenshaw and Hayes (1965).) Commonly in practice, the lowest (for example) data values x1,s, while not being approximately constant, do lie close to some smooth curve in the x,y plane. Using values from this curve as the values of xmin, different in general on each line, causes the lowest transformed data values x-1,s to be approximately constant. Sometimes, appropriate curves for xmax and xmin will be clear from the context of the problem (they need not be polynomials). If this is not the case, suitable curves can often be obtained by fitting to the lowest data values x1,s and to the corresponding highest data values of x, low degree polynomials in y, using function nag_1d_cheb_fit (e02adc), and then shifting the two curves outwards by a small amount so that they just contain all the data between them. The complete curves are not in fact supplied to the present function, only their values at each ys; and the values simply need to lie on smooth curves. More values on the complete curves will be required subsequently, when computing values of the fitted surface at arbitrary y values.

Naturally, a satisfactory approximation to the surface underlying the data cannot be expected if the character of the surface is not adequately represented by the data. Also, as always with polynomials, the approximating function may exhibit unwanted oscillations (particularly near the ends of the ranges) if the degrees k and l are taken greater than certain values, generally unknown but depending on the total number of coefficients k+1×l+1 should be significantly smaller than, say not more than half, the total number of data points. Similarly, k+1 should be significantly smaller than most (preferably all) the ms, and l+1 significantly smaller than n. Closer spacing of the data near the ends of the x and y ranges is an advantage. In particular, if y-s=-cosπs-1/n-1, for s=1,2,…,n and x-r,s=-cosπr-1/m-1, for r=1,2,…,m, (thus ms=m for all s), then the values k=m-1 and l=n-1 (so that the polynomial passes exactly through all the data points) should not give unwanted oscillations. Other datasets should be similarly satisfactory if they are everywhere at least as closely spaced as the above cosine values with m replaced by k+1 and n by l+1 (more precisely, if for every s the largest interval between consecutive values of arccos⁡x-r,s, for r=1,2,…,m, is not greater than π/k, and similarly for the y-s). The polynomial obtained should always be examined graphically before acceptance. Note that, for this purpose it is not sufficient to plot the polynomial only at the data values of x and y: intermediate values should also be plotted, preferably via a graphics facility.

Provided the data are adequate, and the surface underlying the data is of a form that can be represented by a polynomial of the chosen degrees, the function should produce a good approximation to this surface. It is not, however, the true least squares surface fit nor even a polynomial in x and y, the original variables (see Section 6 of Clenshaw and Hayes (1965), ), except in certain special cases. The most important of these is where the data values of x are the same on each line y=ys, (i.e., the data points lie on a rectangular mesh in the x,y plane), the weights of the data points are all equal, and xmax and xmin are both constants (in this case they should be set to the largest and smallest data values of x, respectively).

If the dataset is such that it can be satisfactorily approximated by a polynomial of degrees k′ and l′, say, then if higher values are used for k and l in the function, all the coefficients aij for i>k′ or j>l′ will take apparently random values within a range bounded by the size of the data errors, or rather less. (This behaviour of the Chebyshev coefficients, most readily observed if they are set out in a rectangular array, closely parallels that in curve-fitting, examples of which are given in Section 8 of Hayes (1970).) In practice, therefore, to establish suitable values of k′ and l′, you should first be seeking (within the limitations discussed above) values for k and l which are large enough to exhibit the behaviour described. Values for k′ and l′ should then be chosen as the smallest which do not exclude any coefficients significantly larger than the random ones. A polynomial of degrees k′ and l′ should then be fitted to the data.

If the option to force the fit to contain a given polynomial factor in x is used and if zeros of the chosen factor coincide with data x values on any line, then the effective number of data points on that line is reduced by the number of such coincidences. A similar consideration applies when forcing the y-direction. No account is taken of this by the function when testing that the degrees k and l have not been chosen too large.

10 Example

This example reads data in the following order, using the notation of the argument list for nag_2d_cheb_fit_lines (e02cac) above: