NAG FL Interface
e02agf (dim1_cheb_con)
1
Purpose
e02agf 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.
2
Specification
Fortran Interface
Subroutine e02agf ( |
m, kplus1, lda, xmin, xmax, x, y, w, mf, xf, yf, lyf, ip, a, s, np1, wrk, lwrk, iwrk, liwrk, ifail) |
Integer, Intent (In) |
:: |
m, kplus1, lda, mf, lyf, ip(mf), lwrk, liwrk |
Integer, Intent (Inout) |
:: |
ifail |
Integer, Intent (Out) |
:: |
np1, iwrk(liwrk) |
Real (Kind=nag_wp), Intent (In) |
:: |
xmin, xmax, x(m), y(m), w(m), xf(mf), yf(lyf) |
Real (Kind=nag_wp), Intent (Inout) |
:: |
a(lda,kplus1) |
Real (Kind=nag_wp), Intent (Out) |
:: |
s(kplus1), wrk(lwrk) |
|
C Header Interface
#include <nag.h>
void |
e02agf_ (const Integer *m, const Integer *kplus1, const Integer *lda, const double *xmin, const double *xmax, const double x[], const double y[], const double w[], const Integer *mf, const double xf[], const double yf[], const Integer *lyf, const Integer ip[], double a[], double s[], Integer *np1, double wrk[], const Integer *lwrk, Integer iwrk[], const Integer *liwrk, Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
e02agf_ (const Integer &m, const Integer &kplus1, const Integer &lda, const double &xmin, const double &xmax, const double x[], const double y[], const double w[], const Integer &mf, const double xf[], const double yf[], const Integer &lyf, const Integer ip[], double a[], double s[], Integer &np1, double wrk[], const Integer &lwrk, Integer iwrk[], const Integer &liwrk, Integer &ifail) |
}
|
The routine may be called by the names e02agf or nagf_fit_dim1_cheb_con.
3
Description
e02agf 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 to be 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 values , for , specified by you, 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 routine produces the values of the coefficients
, for
, together with the value of the root mean square residual,
where
is the number of data points with nonzero weight.
Values of the approximations may subsequently be computed using
e02aef or
e02akf.
First
e02agf 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)).
4
References
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
5
Arguments
-
1:
– Integer
Input
-
On entry: , the number of data points to be fitted.
Constraint:
.
-
2:
– Integer
Input
-
On entry: , where is the maximum degree required.
Constraint:
is the total number of constraints and is the number of data points with nonzero weights and distinct abscissae which do not coincide with any of the .
-
3:
– Integer
Input
-
On entry: the first dimension of the array
a as declared in the (sub)program from which
e02agf is called.
Constraint:
.
-
4:
– Real (Kind=nag_wp)
Input
-
5:
– Real (Kind=nag_wp)
Input
-
On entry: the lower and upper end points, respectively, of the interval
. Unless there are specific reasons to the contrary, it is recommended that
xmin and
xmax be set respectively to the lowest and highest value among the
and
. This avoids the danger of extrapolation provided there is a constraint point or data point with nonzero weight at each end point.
Constraint:
.
-
6:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain the value of the independent variable at the th data point, for .
Constraint:
the must be in nondecreasing order and satisfy .
-
7:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain , the value of the dependent variable at the th data point, for .
-
8:
– Real (Kind=nag_wp) array
Input
-
On entry:
must contain the weight
to be applied to the data point
, for
. For advice on the choice of weights see the
E02 Chapter Introduction. Negative weights are treated as positive. A zero weight causes the corresponding data point to be ignored. Zero weight should be given to any data point whose
and
values both coincide with those of a constraint (otherwise the denominators involved in the root mean square residuals
will be slightly in error).
-
9:
– Integer
Input
-
On entry: , the number of values of the independent variable at which a constraint is specified.
Constraint:
.
-
10:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain , the value of the independent variable at which a constraint is specified, for .
Constraint:
these values need not be ordered but must be distinct and satisfy .
-
11:
– Real (Kind=nag_wp) array
Input
-
On entry: the values which the approximating polynomials and their derivatives are required to take at the points specified in
xf. For each value of
,
yf contains in successive elements the required value of the approximation, its first derivative, second derivative,
th derivative, for
. Thus the value,
, which the
th derivative of each approximation (
referring to the approximation itself) is required to take at the point
must be contained in
, where
where
and
. The derivatives are with respect to the independent variable
.
-
12:
– Integer
Input
-
On entry: the dimension of the array
yf as declared in the (sub)program from which
e02agf is called.
Constraint:
.
-
13:
– Integer array
Input
-
On entry: must contain , the order of the highest-order derivative specified at , for . implies that the value of the approximation at is specified, but not that of any derivative.
Constraint:
, for .
-
14:
– Real (Kind=nag_wp) array
Output
-
On exit: contains the coefficient in the approximating polynomial of degree , for and .
-
15:
– Real (Kind=nag_wp) array
Output
-
On exit:
contains
, for
, the root mean square residual corresponding to the approximating polynomial of degree
. In the case where the number of data points with nonzero weight is equal to
,
is indeterminate: the routine sets it to zero. For the interpretation of the values of
and their use in selecting an appropriate degree, see
Section 3.1 in the
E02 Chapter Introduction.
-
16:
– Integer
Output
-
On exit: , where is the total number of constraint conditions imposed: .
-
17:
– Real (Kind=nag_wp) array
Output
-
On exit: contains weighted residuals of the highest degree of fit determined . The residual at
is in element , for . The rest of the array is used as workspace.
-
18:
– Integer
Input
-
On entry: the dimension of the array
wrk as declared in the (sub)program from which
e02agf is called.
Constraint:
, where , for .
-
19:
– Integer array
Workspace
-
20:
– Integer
Input
-
On entry: the dimension of the array
iwrk as declared in the (sub)program from which
e02agf is called.
Constraint:
.
-
21:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, and .
Constraint: , where N is the total number of constraints.
On entry, and .
Constraint: .
On entry,
liwrk is too small.
. Minimum possible dimension:
.
On entry,
lwrk is too small.
. Minimum possible dimension:
.
On entry, and .
Constraint: , where N is the total number of constraints.
On entry, .
Constraint: .
On entry, .
Constraint: .
-
On entry, and .
Constraint: .
-
On entry, , , and .
Constraint: .
On entry, lies outside interval : , , and .
On entry, and .
Constraint: .
-
On entry, lies outside interval : , , and .
On entry, lies outside interval for some .
-
On entry, , and .
Constraint: .
-
On entry,
, where
mdist is the number of data points with nonzero weight and distinct abscissae different from all
xf, and
N is the total number of constraints:
,
and
.
-
The polynomials and/or cannot be found. The problem is too ill-conditioned. This may occur when the constraint points are very close together, or large in number, or when an attempt is made to constrain high-order derivatives.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
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 routine.
8
Parallelism and Performance
e02agf is not threaded in any implementation.
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
e02adf. To carry out polynomial interpolation only, use
e01aef.
10
Example
This example reads data in the following order, using the notation of the argument list above:
- mf
- ,
,
Y-value and derivative values (if any) at , for
- m
- ,
,
, for
- , xmin, xmax
The output is:
- the root mean square residual for each degree from to ;
- the Chebyshev coefficients for the fit of degree ;
- the data points, and the fitted values and residuals for the fit of degree .
The program is written in a generalized form which will read any number of datasets.
The dataset supplied specifies
data points in the interval
with unit weights, to which are to be fitted polynomials,
, of degrees up to
, subject to the
constraints:
10.1
Program Text
10.2
Program Data
10.3
Program Results