POLYFIT Fit polynomial to data. POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense. [P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a structure S for use with POLYVAL to obtain error estimates on predictions. If the errors in the data, Y, are independent normal with constant variance, POLYVAL will produce error bounds which contain at least 50% of the predictions. The structure S contains the Cholesky factor of the Vandermonde matrix (R), the degrees of freedom (df), and the norm of the residuals (normr) as fields. [P,S,MU] = POLYFIT(X,Y,N) finds the coefficients of a polynomial in XHAT = (X-MU(1))/MU(2) where MU(1) = mean(X) and MU(2) = std(X). This centering and scaling transformation improves the numerical properties of both the polynomial and the fitting algorithm. Warning messages result if N is >= length(X), if X has repeated, or nearly repeated, points, or if X might need centering and scaling. See also POLY, POLYVAL, ROOTS.