NAG Library Function Document
nag_1d_cheb_fit (e02adc) computes weighted least squares polynomial approximations to an arbitrary set of data points.
||nag_1d_cheb_fit (Integer m,
const double x,
const double y,
const double w,
nag_1d_cheb_fit (e02adc) determines least squares polynomial approximations of degrees to the set of data points with weights , for .
The approximation of degree
has the property that it minimizes
the sum of squares of the weighted residuals
is the value of the polynomial of degree
th data point.
Each polynomial is represented in Chebyshev series form with normalized argument
. This argument lies in the range
and is related to the original variable
by the linear transformation
are respectively the largest and smallest values of
. The polynomial approximation of degree
is represented as
is the Chebyshev polynomial of the first kind of degree
For , the function produces the values of , for , together with the value of the root mean square residual . In the case the function sets the value of to zero.
The method employed is due to Forsythe (1957)
and is based upon the generation of a set of polynomials orthogonal with respect to summation over the normalized dataset. The extensions due to Clenshaw (1960)
to represent these polynomials as well as the approximating polynomials in their Chebyshev series forms are incorporated. The modifications suggested by Reinsch and Gentleman (Gentleman (1969)
) to the method originally employed by Clenshaw for evaluating the orthogonal polynomials from their Chebyshev series representations are used to give greater numerical stability.
For further details of the algorithm and its use see Cox (1974)
, Cox and Hayes (1973)
Subsequent evaluation of the Chebyshev series representations of the polynomial approximations should be carried out using nag_1d_cheb_eval (e02aec)
Clenshaw C W (1960) Curve fitting with a digital computer Comput. J. 2 170–173
Cox M G (1974) A data-fitting package for the non-specialist user Software for Numerical Mathematics (ed D J Evans) Academic Press
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
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
Gentleman W M (1969) An error analysis of Goertzel's (Watt's) method for computing Fourier coefficients Comput. J. 12 160–165
Hayes J G (ed.) (1970) Numerical Approximation to Functions and Data Athlone Press, London
m – IntegerInput
On entry: the number of data points.
, where is the number of distinct values in the data.
kplus1 – IntegerInput
On entry: , where is the maximum degree required.
, where is the number of distinct values in the data.
tda – IntegerInput
: the stride separating matrix column elements in the array a
x[m] – const doubleInput
On entry: the values of the independent variable, for .
the values must be supplied in non-decreasing order with .
y[m] – const doubleInput
On entry: the values of the dependent variable, for .
w[m] – const doubleInput
: the set of weights,
. For advice on the choice of weights, see the e02 Chapter Introduction
, for .
a – doubleOutput
On exit: the coefficients of in the approximating polynomial of degree . contains the coefficient , for and .
s[kplus1] – doubleOutput
contains the root mean square residual
, as described in Section 3
. For the interpretation of the values of the
and their use in selecting an appropriate degree, see the e02 Chapter Introduction
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, while the number of distinct values, . These arguments must satisfy .
On entry, while .
The arguments must satisfy .
Dynamic memory allocation failed.
On entry, kplus1
must not be less than 1:
On entry, all the in the sequence , are the same.
On entry, the sequence , is not in non-decreasing order.
On entry, the weights are not strictly positive: .
No error analysis for the method has been published. Practical experience with the method, however, is generally extremely satisfactory.
The time taken by nag_1d_cheb_fit (e02adc) is approximately proportional to .
The approximating polynomials may exhibit undesirable oscillations (particularly near the ends of the range) if the maximum degree
exceeds a critical value which depends on the number of data points
and their relative positions. As a rough guide, for equally spaced data, this critical value is about
. For further details see page 60 of Hayes (1970)
Determine weighted least squares polynomial approximations of degrees 0, 1, 2 and 3 to a set of 11 prescribed data points. For the approximation of degree 3, tabulate the data and the corresponding values of the approximating polynomial, together with the residual errors, and also the values of the approximating polynomial at points half-way between each pair of adjacent data points.
The example program supplied is written in a general form that will enable polynomial approximations of degrees
to be obtained to
data points, with arbitrary positive weights, and the approximation of degree
to be tabulated. nag_1d_cheb_eval (e02aec)
is used to evaluate the approximating polynomial. The program is self-starting in that any number of datasets can be supplied.
9.1 Program Text
Program Text (e02adce.c)
9.2 Program Data
Program Data (e02adce.d)
9.3 Program Results
Program Results (e02adce.r)