POLYFIT

Purpose:

Performs a Least Squares Polynomial fit.

Syntax:

POLYFIT(y, x, order, overwrite, form, method, "specfile")

y

-

A series or table.

x

-

Optional. A series or table, the explicit X values. Defaults to the X values of y.

order

-

An integer, the order of the polynomial fit.

overwrite

-

Optional. An integer, the overwrite flag for existing "specfile":

 

 

  -1:

does not write a file (default)

   0:

prompt to overwrite file

   1:

does not prompt to overwrite file

form

-

Optional. An integer, the polynomial coefficient form:

 

 

   0:

ascending powers, lowest degree to highest (default)

   1:

decreasing powers, highest degree to lowest.

method

-

Optional. An integer, the least squares fitting method:

 

 

   0:

QR decomposition (default)

   1:

Gauss-Jordan elimination.

"specfile"

-

Optional. A string, the name of summary statistics file. Defaults to "polyN.fit".

Returns:

A series of coefficients.

Example:

W1: gline(100,.01,1.0,1.0)^2
W2: polyfit(W1, 3)

 

returns a 4 point series with values {1.0, 2.0, 1.0, 5.89E-14} as the resulting 3rd order coefficients, a[1], a[2], a[3], a[4].

 

W3: polygraph(W2, xvals(W1))

 

graphs the fit.

Example:

POLYFIT also works with XY data. For example:

 

W1: xy(gexp(100, 0.01), gsin(100, 0.01))

W2: polyfit(W1, 5)

W3: polyfit(W1, xvals(W1), 5)

W4: polygraph(W2, xvals(W1), 1)

 

W2 and W3 produce the same coefficients. The last parameter of 1 in the POLYGRAPH function creates an explicit XY graph.

Remarks:

polyfit(series, N) performs a least squares fit of a series to

 

image\polyf04.gif

 

where y is the input series and N is the order of the fit.

 

POLYFIT returns the coefficients, a[k], of the above power series.

 

If form is 1 then:

 

image\polyf03.gif

 

The default QR decomposition method (method = 0) is slower, but more accurate than the Gauss-Jordan elimination method and is preferred for high order fits. However, Gauss-Jordan may be preferred for low order fits where speed is an important factor.

 

For a tabular view of the coefficients, use the TABLEVIEW function in the Window containing the results of the POLYFIT operation.

 

See PFIT to fit a polynomial with error statistics.

 

See LINFIT to fit linear combination of arbitrary basis functions to a series using the method of least squares.

 

See POLYGRAPH or POLYVAL to evaluate the resulting polynomial.

 

See DADiSP/MatrixXL to significantly optimize POLYFIT for the QR method.

See Also:

DADiSP/MatrixXL

INTERPOLATE

LFIT

LINFIT

LINREG

LINREG2

PFIT

POLYGRAPH

POLYVAL

QR

SPLINE

TREND

XY

XYINTERP