|
NAG[e02cac] NAG[nag_2d_cheb_fit_lines] - Least-squares surface fit by polynomials, data on lines
|
|
Calling Sequence
e02cac(m, k, l, x, y, f, w, a, xmin, xmax, nux, nuy, 'n'=n, 'inuxp1'=inuxp1, 'inuyp1'=inuyp1, 'fail'=fail)
nag_2d_cheb_fit_lines(. . .)
Parameters
|
m - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
Constraint: , for . .
|
|
|
k - integer;
|
|
|
On entry: , the required degree of in the fit.
|
|
|
l - integer;
|
|
|
On entry: , the required degree of in the fit.
|
|
;
|
|
.
|
|
|
x - Vector(1.. , datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array x must be at least .
|
|
On entry: the values of the data points. The sequence must be
|
|
all points on , followed by
|
|
all points on , followed by
|
|
all points on .
|
|
Constraint: for each , the values must be in non-decreasing order. .
|
|
|
y - Vector(1..n, datatype=float[8]);
|
|
|
Constraint: the values must be in strictly increasing order. .
|
|
|
f - Vector(1.. , datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array f must be at least .
|
|
On entry: , the data values of the dependent variable in the same sequence as the values.
|
|
|
w - Vector(1.. , datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array w must be at least .
|
|
|
a - Vector(1.. , datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array a must be at least .
|
|
On exit: contains the Chebyshev coefficients of the fit. is the coefficient of Section [Description] defined according to the standard convention. These coefficients are used by e02cbc (nag_2d_cheb_eval) to calculate values of the fitted function.
|
|
|
xmin - Vector(1..n, datatype=float[8]);
|
|
|
|
xmax - Vector(1..n, datatype=float[8]);
|
|
|
Constraint: . .
|
|
|
nux - Vector(1..inuxp1, datatype=float[8]);
|
|
|
Constraint: must be non-zero, unless , in which case nux is ignored. .
|
|
|
nuy - Vector(1..inuyp1, datatype=float[8]);
|
|
|
Constraint: must be non-zero, unless , in which case nuy is ignored. .
|
|
|
'n'=n - integer; (optional)
|
|
|
On entry: the number of lines constant on which data points are given.
|
|
Constraint: . .
|
|
|
'inuxp1'=inuxp1 - integer; (optional)
|
|
|
If this option is not required, inuxp1 should be set equal to 1.
|
|
Constraint: . .
|
|
|
'inuyp1'=inuyp1 - integer; (optional)
|
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_2d_cheb_fit_lines (e02cac) forms an approximation to the weighted, least-squares Chebyshev-series surface fit to data arbitrarily distributed on lines parallel to one independent co-ordinate axis.
|
|
Description
|
|
This function determines a bivariate polynomial approximation of degree in and in to the set of data points , with weights , for and . That is, the data points are on lines , but the values may be different on each line. The values of and are prescribed by you (for guidance on their choice, see Section [Further Comments]). The function is based on the method described in Clenshaw and Hayes (1965), Sections 5 and 6.
The polynomial is represented in double Chebyshev-series form with arguments and . The arguments lie in the range to and are related to the original variables and by the transformations
Here and are set by the function to, respectively, the largest and smallest value of , but and are functions of prescribed by you (see Section [Further Comments]). For this function, only their values and at each are required. For each , must not be less than the largest on the line , and, similarly, must not be greater than the smallest .
The double Chebyshev-series can be written as
where is the Chebyshev polynomial of the first kind of degree with argument , and is similarly defined. However, the standard convention, followed in this function, is that coefficients in the above expression which have either or zero are written as , instead of simply , and the coefficient with both and equal to zero is written as . The series with coefficients output by the function should be summed using this convention. e02cbc (nag_2d_cheb_eval) is available to compute values of the fitted function from these coefficients.
The function first obtains Chebyshev-series coefficients , for , of the weighted least-squares polynomial curve fit of degree in to the data on each line , for in turn, using an auxiliary function. The same function is then called times to fit , for by a polynomial of degree in , for each . The resulting coefficients are the required .
You can be 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 , , and or indeed along any lines constant or constant (see Clenshaw and Hayes (1965), Section 8).
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_BAD_PARAM"
On entry, argument had an illegal value.
"NE_INT"
On entry, . Constraint: .
On entry, . Constraint: .
On entry, . Constraint: .
On entry, . Constraint: .
On entry, . Constraint: .
"NE_INT_2"
On entry, : , .
On entry, : , .
"NE_INT_3"
On entry, : , , .
On entry, , , . Constraint: .
On entry, , , . Constraint: and
"NE_INT_ARRAY"
On entry, : , , .
On entry, , . Constraint: , for .
On entry, and inuxp1 is not equal to 1, or and inuyp1 is not equal to 1: , , .
"NE_INTERNAL_ERROR"
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
"NE_NON_ZERO_WEIGHTS"
On entry, the number of distinct x values with non-zero weight on is less than : , , .
"NE_NOT_NON_DECREASING"
On entry, the data x values are not non-decreasing for : , .
"NE_NOT_STRICTLY_INCREASING"
On entry, : , , .
"NE_REAL_ARRAY"
On entry, and do not span the data x values on : , , .
|
|
Accuracy
|
|
No error analysis for this method has been published. Practical experience with the method, however, is generally extremely satisfactory.
|
|
Further Comments
|
|
The time taken is approximately proportional to .
The reason for allowing and (which are used to normalize the range of ) to vary with is that unsatisfactory fits can result if the highest (or lowest) data values of the normalized on each line 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 , while not being approximately constant, do lie close to some smooth curve in the plane. Using values from this curve as the values of , different in general on each line, causes the lowest transformed data values to be approximately constant. Sometimes, appropriate curves for and 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 and to the corresponding highest data values of , low degree polynomials in , using function e02adc (nag_1d_cheb_fit), 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 ; 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 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 and are taken greater than certain values, generally unknown but depending on the total number of coefficients should be significantly smaller than, say not more than half, the total number of data points. Similarly, should be significantly smaller than most (preferably all) the , and significantly smaller than . Closer spacing of the data near the ends of the and ranges is an advantage. In particular, if , for and , for , (thus for all ), then the values and (so that the polynomial passes exactly through all the data points) should not give unwanted oscillations. Other data sets should be similarly satisfactory if they are everywhere at least as closely spaced as the above cosine values with replaced by and by (more precisely, if for every the largest interval between consecutive values of , for , is not greater than , and similarly for the ). 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 and : 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 and , the original variables (see Clenshaw and Hayes (1965), Section 6), except in certain special cases. The most important of these is where the data values of are the same on each line , (i.e., the data points lie on a rectangular mesh in the plane), the weights of the data points are all equal, and and are both constants (in this case they should be set to the largest and smallest data values of , respectively).
If the data set is such that it can be satisfactorily approximated by a polynomial of degrees and , say, then if higher values are used for and in the function, all the coefficients for or 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 Hayes (1970), Section 8.) In practice, therefore, to establish suitable values of and , you should first be seeking (within the limitations discussed above) values for and which are large enough to exhibit the behaviour described. Values for and should then be chosen as the smallest which do not exclude any coefficients significantly larger than the random ones. A polynomial of degrees and should then be fitted to the data.
If the option to force the fit to contain a given polynomial factor in is used and if zeros of the chosen factor coincide with data 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 -direction. No account is taken of this by the function when testing that the degrees and have not been chosen too large.
|
|
|
Examples
|
|
>
|
n := 4:
k := 3:
l := 2:
inuxp1 := 1:
inuyp1 := 1:
m := Vector([8, 7, 7, 6], datatype=integer[kernelopts('wordsize')/8]):
x := Vector([0.1, 1, 1.6, 2.1, 3.3, 3.9, 4.2, 4.9, 0.1, 1.1, 1.9, 2.7, 3.2, 4.1, 4.5, 0.5, 1.1, 1.3, 2.2, 2.9, 3.5, 3.9, 1.7, 2, 2.4, 2.7, 3.1, 3.5], datatype=float[8]):
y := Vector([0, 1, 2, 4], datatype=float[8]):
f := Vector([1.01005, 1.10517, 1.17351, 1.23368, 1.39097, 1.47698, 1.52196, 1.63232, 2.0201, 2.23256, 2.4185, 2.61993, 2.75426, 3.01364, 3.13662, 3.15381, 3.34883, 3.41649, 3.73823, 4.00928, 4.2572, 4.43094, 5.92652, 6.10701, 6.35625, 6.54982, 6.81713, 7.09534], datatype=float[8]):
w := Vector([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], datatype=float[8]):
a := Vector(12, datatype=float[8]):
xmin := Vector([0, 0.1, 0.4, 1.6], datatype=float[8]):
xmax := Vector([5, 4.5, 4, 3.5], datatype=float[8]):
nux := Vector([0], datatype=float[8]):
nuy := Vector([0], datatype=float[8]):
NAG:-e02cac(m, k, l, x, y, f, w, a, xmin, xmax, nux, nuy, 'n' = n, 'inuxp1' = inuxp1, 'inuyp1' = inuyp1):
|
|
|