|
NAG[e02agc] NAG[nag_1d_cheb_fit_constr] - Least-squares polynomial fit, values and derivatives may be constrained, arbitrary data points
|
|
Calling Sequence
e02agc(k, xmin, xmax, x, y, w, xf, yf, p, a, s, n, resid, 'm'=m, 'mf'=mf, 'fail'=fail)
nag_1d_cheb_fit_constr(. . .)
Parameters
|
k - integer;
|
|
|
On entry: , the maximum degree required.
|
|
|
xmin - float;
xmax - float;
|
|
|
Constraint: . .
|
|
|
x - Vector(1..m, datatype=float[8]);
|
|
|
Constraint: the must be in non-decreasing order and satisfy . .
|
|
|
y - Vector(1..m, datatype=float[8]);
|
|
|
|
w - Vector(1..m, datatype=float[8]);
|
|
|
|
xf - Vector(1..mf, datatype=float[8]);
|
|
|
Constraint: these values need not be ordered but must be distinct and satisfy . .
|
|
|
yf - Vector(1.. , datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array yf must be at least .
|
|
|
p - Vector(1..mf, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
Constraint: , for . .
|
|
|
a - Matrix(1.. , 1.. , datatype=float[8], order=order);
|
|
|
Note: this array may be supplied in Fortran_order or C_order , as specified by order. All array parameters must use a consistent order.
|
|
Note: the dimension, dim, of the array a must be at least .
|
|
|
s - Vector(1.. , datatype=float[8]);
|
|
|
|
n - assignable;
|
|
|
Note: On exit the variable n will have a value of type integer.
|
|
On exit: contains the total number of constraint conditions imposed: .
|
|
|
resid - Vector(1..m, datatype=float[8]);
|
|
|
|
'm'=m - integer; (optional)
|
|
|
On entry: the number of data points to be fitted.
|
|
Constraint: . .
|
|
|
'mf'=mf - integer; (optional)
|
|
|
On entry: the number, of values of the independent variable at which a constraint is specified.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_1d_cheb_fit_constr (e02agc) computes constrained weighted least-squares polynomial approximations in Chebyshev-series form to an arbitrary set of data points. The values of the approximations and any number of their derivatives can be specified at selected points.
|
|
Description
|
|
nag_1d_cheb_fit_constr (e02agc) determines least-squares polynomial approximations of degrees up to to the set of data points with weights , for . The value of , the maximum degree required, is prescribed by you. At each of the values , for , of the independent variable , the approximations and their derivatives up to order are constrained to have one of the user-specified values , for , where .
The approximation of degree has the property that, subject to the imposed constraints, it minimizes , the sum of the squares of the weighted residuals , for , where
and is the value of the polynomial approximation of degree at the th data point.
Each polynomial is represented in Chebyshev-series form with normalized argument . This argument lies in the range to and is related to the original variable by the linear transformation
where and , specified by you, are respectively the lower and upper end points of the interval of over which the polynomials are to be defined.
The polynomial approximation of degree can be written as
where is the Chebyshev polynomial of the first kind of degree with argument . For , the function produces the values of the coefficients , for , together with the value of the root-mean-square residual, , defined as
where is the number of data points with non-zero weight.
Values of the approximations may subsequently be computed using e02aec (nag_1d_cheb_eval) or e02akc (nag_1d_cheb_eval2).
First nag_1d_cheb_fit_constr (e02agc) determines a polynomial , of degree , which satisfies the given constraints, and a polynomial , of degree , which has value (or derivative) zero wherever a constrained value (or derivative) is specified. It then fits , for , with polynomials of the required degree in each with factor . Finally the coefficients of are added to the coefficients of these fits to give the coefficients of the constrained polynomial approximations to the data points , for . The method employed is given in Hayes (1970): it is an extension of Forsythe's orthogonal polynomials method (see Forsythe (1957)) as modified by Clenshaw (see Clenshaw (1960)).
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_BAD_PARAM"
On entry, argument had an illegal value.
"NE_ILL_CONDITIONED"
The polynomials and/or cannot be found. The problem is too ill-conditioned.
"NE_INT"
On entry, . Constraint: .
On entry, . Constraint: .
"NE_INT_3"
On entry, , where is the number of data points with non-zero weight and distinct abscissae different from all the xf, and n is the total number of constraints: , , .
"NE_INT_ARRAY"
On entry, , . Constraint: , for .
"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_NOT_MONOTONIC"
On entry, : , , .
"NE_REAL_2"
On entry, : , .
"NE_REAL_ARRAY"
On entry, : , , , .
On entry, lies outside interval : , , , .
On entry, lies outside interval : , , , .
On entry, lies outside interval for some .
|
|
Accuracy
|
|
No complete error analysis exists for either the interpolating algorithm or the approximating algorithm. However, considerable experience with the approximating algorithm shows that it is generally extremely satisfactory. Also the moderate number of constraints, of low-order, which are typical of data fitting applications, are unlikely to cause difficulty with the interpolating function.
|
|
Further Comments
|
|
The time taken to form the interpolating polynomial is approximately proportional to , and that to form the approximating polynomials is very approximately proportional to .
To carry out a least-squares polynomial fit without constraints, use e02adc (nag_1d_cheb_fit). To carry out polynomial interpolation only, use e01aec (nag_1d_cheb_interp).
|
|
|
Examples
|
|
>
|
m := 5:
k := 4:
xmin := 0:
xmax := 4:
mf := 2:
x := Vector([0.5, 1, 2, 2.5, 3], datatype=float[8]):
y := Vector([0.03, -0.75, -1, -0.1, 1.75], datatype=float[8]):
w := Vector([1, 1, 1, 1, 1], datatype=float[8]):
xf := Vector([0, 4], datatype=float[8]):
yf := Vector([1, -2, 9], datatype=float[8]):
p := Vector([1, 0], datatype=integer[kernelopts('wordsize')/8]):
a := Matrix(5, 5, datatype=float[8]):
s := Vector(5, datatype=float[8]):
resid := Vector(5, datatype=float[8]):
NAG:-e02agc(k, xmin, xmax, x, y, w, xf, yf, p, a, s, n, resid, 'm' = m, 'mf' = mf):
|
|
|
See Also
|
|
Clenshaw C W (1960) Curve fitting with a digital computer Comput. J. 2 170–173
Forsythe G E (1957) Generation and use of orthogonal polynomials for data fitting with a digital computer J. Soc. Indust. Appl. Math. 5 74–88
Hayes J G (ed.) (1970) Numerical Approximation to Functions and Data Athlone Press, London
e02 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|