The POLY_FIT function performs a least-square polynomial fit with optional weighting and returns a vector of coefficients.
The POLY_FIT routine uses matrix inversion to determine the coefficients. A different version of this routine, SVDFIT, uses singular value decomposition (SVD). The SVD technique is more flexible and robust, but may be slower.
This routine is written in the IDL language. Its source code can be found in the file poly_fit.pro in the lib subdirectory of the IDL distribution.
Result = POLY_FIT( X, Y, Degree [, CHISQ=variable] [, COVAR=variable] [, /DOUBLE] [, MEASURE_ERRORS=vector] [, SIGMA=variable] [, STATUS=variable] [, YBAND=variable] [, YERROR=variable] [, YFIT=variable] )
POLY_FIT returns a vector of coefficients of length Degree+1. If the DOUBLE keyword is set, or if X or Y are double precision, then the result will be double precision, otherwise the result will be single precision.
An n-element vector of independent variables.
A vector of dependent variables, the same length as X.
The degree of the polynomial to fit.
The Yfit, Yband, Sigma, and Corrm arguments are obsolete, and have been replaced by the YFIT, YBAND, YERROR, and COVAR keywords, respectively. Code using these arguments will continue to work as before, but new code should use the keywords instead.
Set this keyword to a named variable that will contain the value of the unreduced chi-square goodness-of-fit statistic.
Set this keyword to a named variable that will contain the Covariance matrix of the coefficients.
| Note |
Set this keyword to force computations to be done in double-precision arithmetic. All computations are performed using double-precision arithmetic.
Set this keyword to a vector containing standard measurement errors for each point Y[i]. This vector must be the same length as X and Y.
| Note |
Set this keyword to a named variable that will contain the 1-sigma uncertainty estimates for the returned parameters.
| Note |
Set this keyword to a named variable to receive the status of the operation. Possible status values are:
| Note |
| Tip |
Set this keyword to a named variable that will contain the 1 standard deviation error estimate for each point.
Set this keyword to a named variable that will contain the standard error between YFIT and Y.
Set this keyword to a named variable that will contain the vector of calculated Y values. These values have an error of + or - YBAND.
In this example, we use X and Y data corresponding to the known polynomial f (x) = 0.25 - x + x2. Using POLY_FIT to compute a second degree polynomial fit returns the exact coefficients (to within machine accuracy).
; Define an 11-element vector of independent variable data:
X = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
; Define an 11-element vector of dependent variable data:
Y = [0.25, 0.16, 0.09, 0.04, 0.01, 0.00, 0.01, 0.04, 0.09, $
0.16, 0.25]
; Define a vector of measurement errors:
measure_errors = REPLICATE(0.01, 11)
; Compute the second degree polynomial fit to the data:
result = POLY_FIT(X, Y, 2, MEASURE_ERRORS=measure_errors, $
SIGMA=sigma)
; Print the coefficients:
PRINT, 'Coefficients: ', result
PRINT, 'Standard errors: ', sigma
IDL prints:
Coefficients: 0.250000 -1.00000 1.00000 Standard errors: 0.00761853 0.0354459 0.0341395
Introduced: Original
COMFIT, CURVEFIT, GAUSSFIT, LINFIT, REGRESS, SFIT, SVDFIT