POLY_FIT

The POLY_FIT function performs a least-square polynomial fit with optional error estimates and returns a vector of coefficients with a length of NDegree +1.

The POLY_FIT routine uses matrix inversion. A newer version of this routine, SVDFIT, uses Singular Value Decomposition. The SVD technique is more flexible, but slower. Another version of this routine, POLYFITW, performs a weighted least square fit.

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.

Calling Sequence

Result = POLY_FIT( X, Y, NDegree [,Yfit, Yband, Sigma, Corrm] )

Arguments

X

An n -element vector of independent variables.

Y

A vector of dependent variables, the same length as X .

NDegree

The degree of the polynomial to fit.

Yfit

A named variable that will contain the vector of calculated Y values. These values have an error of plus or minus Yband .

Yband

A named variable that will contain the error estimate for each point.

Sigma

A named variable that will contain the standard deviation in Y units.

Corrm

A named variable that will contain the correlation matrix of the coefficients.

Keywords

DOUBLE

Set this keyword to force computations to be done in double-precision arithmetic.

Example

In this example, we use X and Y data corresponding to the known polynomial f  ( x ) = 0.25 - x + x 2 . Using POLY_FIT to compute a second degree polynomial fit returns the exact coefficients (to within machine accuracy).

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 independent 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 an 11-element vector of dependent variable data.

result = POLY_FIT(X, Y, 2) ; Compute the second degree polynomial fit to the data.

PRINT, result ; Print the coefficients.

IDL prints:

 0.24999996

-0.99999974

 0.99999975

See Also

COMFIT , CURVEFIT , GAUSSFIT , POLYFITW , REGRESS , SFIT , SVDFIT