naginterfaces.library.fit.dim1_cheb_con¶
- naginterfaces.library.fit.dim1_cheb_con(k, xmin, xmax, x, y, w, xf, yf, ip)[source]¶
dim1_cheb_con
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.For full information please refer to the NAG Library document for e02ag
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/e02/e02agf.html
- Parameters
- kint
, the maximum degree required.
- xminfloat
The lower and upper end points, respectively, of the interval . Unless there are specific reasons to the contrary, it is recommended that and 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.
- xmaxfloat
The lower and upper end points, respectively, of the interval . Unless there are specific reasons to the contrary, it is recommended that and 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.
- xfloat, array-like, shape
must contain the value of the independent variable at the th data point, for .
- yfloat, array-like, shape
must contain , the value of the dependent variable at the th data point, for .
- wfloat, array-like, shape
must contain the weight to be applied to the data point , for . For advice on the choice of weights see the E02 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).
- xffloat, array-like, shape
must contain , the value of the independent variable at which a constraint is specified, for .
- yffloat, array-like, shape
The values which the approximating polynomials and their derivatives are required to take at the points specified in . For each value of , 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 .
- ipint, array-like, shape
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.
- Returns
- afloat, ndarray, shape
contains the coefficient in the approximating polynomial of degree , for , for .
- sfloat, ndarray, shape
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 function sets it to zero. For the interpretation of the values of and their use in selecting an appropriate degree, see the E02 Introduction.
- nint
Contains the total number of constraint conditions imposed: .
- residfloat, ndarray, shape
Contains weighted residuals of the highest degree of fit determined . The residual at is in element , for .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, , , and .
Constraint: .
- (errno )
On entry, lies outside interval : , , and .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, lies outside interval for some .
- (errno )
On entry, lies outside interval : , , and .
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, , where is the number of data points with nonzero weight and distinct abscissae different from all , and is the total number of constraints: , and .
- (errno )
The polynomials and/or cannot be found. The problem is too ill-conditioned.
- Notes
dim1_cheb_con
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 function 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
dim1_cheb_eval()
ordim1_cheb_eval2()
.First
dim1_cheb_con
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)).
- 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