polyfit [analysis] [statistics] [octave/scripts/polynomial/polyfit.m]

[p, s] = polyfit (x, y, n) Function File
Return the coefficients of a polynomial p(x) of degree n that minimizes sumsq (p(x(i)) - y(i)), to best fit the data in the least squares sense.

The polynomial coefficients are returned in a row vector.

If two output arguments are requested, the second is a structure containing the following fields:

R
The Cholesky factor of the Vandermonde matrix used to compute the polynomial coefficients.
X
The Vandermonde matrix used to compute the polynomial coefficients.
df
The degrees of freedom.
normr
The norm of the residuals.
yf
The values of the polynomial for each value of x.