POLFIT(3)

SYNOPSIS
SUBROUTINE POLFIT (N, X, Y, W, MAXDEG, NDEG, EPS, R, IERR, A)

NAME
polfit - Fit discrete data in a least squares sense by polynomials in one variable.

LIBRARY
SLATEC

CATEGORY
K1A1A2

TYPE
SINGLE PRECISION (POLFIT-S, DPOLFT-D)

KEYWORDS
CURVE FITTING, DATA FITTING, LEAST SQUARES, POLYNOMIAL FIT

AUTHOR
Shampine, L. F., (SNLA) Davenport, S. M., (SNLA) Huddleston, R. E., (SNLL)

DESCRIPTION
Abstract Given a collection of points X(I) and a set of values Y(I) which correspond to some function or measurement at each of the X(I), subroutine POLFIT computes the weighted least-squares polynomial fits of all degrees up to some degree either specified by the user or determined by the routine. The fits thus obtained are in orthogonal polynomial form. Subroutine PVALUE may then be called to evaluate the fitted polynomials and any of their derivatives at any point. The subroutine PCOEF may be used to express the polynomial fits as powers of (X-C) for any specified point C. The parameters for POLFIT are Input -- N - the number of data points. The arrays X, Y and W must be dimensioned at least N (N .GE. 1). X - array of values of the independent variable. These values may appear in any order and need not all be distinct. Y - array of corresponding function values. W - array of positive values to be used as weights. If W(1) is negative, POLFIT will set all the weights to 1.0, which means unweighted least squares error will be minimized. To minimize relative error, the user should set the weights to: W(I) = 1.0/Y(I)**2, I = 1,...,N . MAXDEG - maximum degree to be allowed for polynomial fit. MAXDEG may be any non-negative integer less than N. Note -- MAXDEG cannot be equal to N-1 when a statistical test is to be used for degree selection, i.e., when input value of EPS is negative. EPS - specifies the criterion to be used in determining the degree of fit to be computed. (1) If EPS is input negative, POLFIT chooses the degree based on a statistical F test of significance. One of three possible significance levels will be used: .01, .05 or automatically select one of these levels based on the number of data points and the maximum degree to be considered. If EPS is input as -.01, -.05, or -.10, a significance level of (2) If EPS is set to 0., POLFIT computes the polynomials of degrees 0 through MAXDEG . (3) If EPS is input positive, EPS is the RMS error tolerance which must be satisfied by the fitted polynomial. POLFIT will increase the degree of fit until this criterion is met or until the maximum degree is reached. Output -- NDEG - degree of the highest degree fit computed. EPS - RMS error of the polynomial of degree NDEG . R - vector of dimension at least NDEG containing values of the fit of degree NDEG at each of the X(I) . Except when the statistical test is used, these values are more accurate than results from subroutine PVALUE normally are. IERR - error flag with the following possible values. 1 -- indicates normal execution, i.e., either (1) the input value of EPS was negative, and the computed polynomial fit of degree NDEG satisfies the specified F test, or (2) the input value of EPS was 0., and the fits of all degrees up to MAXDEG are complete, or (3) the input value of EPS was positive, and the polynomial of degree NDEG satisfies the RMS error requirement. 2 -- invalid input parameter. At least one of the input parameters has an illegal value and must be corrected before POLFIT can proceed. Valid input results when the following restrictions are observed N .GE. 1 0 .LE. MAXDEG .LE. N-1 for EPS .GE. 0. 0 .LE. MAXDEG .LE. N-2 for EPS .LT. 0. W(1)=-1.0 or W(I) .GT. 0., I=1,...,N . 3 -- cannot satisfy the RMS error requirement with a polynomial of degree no greater than MAXDEG . Best fit found is of degree MAXDEG . 4 -- cannot satisfy the test for significance using current value of MAXDEG . Statistically, the best fit found is of order NORD . (In this case, NDEG will have one of the values: MAXDEG-2, MAXDEG-1, or MAXDEG). Using a higher value of MAXDEG may result in passing the test. A - work and output array having at least 3N+3MAXDEG+3 locations Note - POLFIT calculates all fits of degrees up to and including NDEG . Any or all of these fits can be evaluated or expressed as powers of (X-C) using PVALUE and PCOEF after just one call to POLFIT .

REFERENCES
L. F. Shampine, S. M. Davenport and R. E. Huddleston, Curve fitting by polynomials in one variable, Report SLA-74-0270, Sandia Laboratories, June 1974.

ROUTINES CALLED
PVALUE, XERMSG

REVISION HISTORY (YYMMDD)
740601 DATE WRITTEN
890531 Changed all specific intrinsics to generic. (WRB)
890531 REVISION DATE from Version 3.2
891214 Prologue converted to Version 4.0 format. (BAB)
900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
920501 Reformatted the REFERENCES section. (WRB)
920527 Corrected erroneous statements in DESCRIPTION. (WRB)