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 matrix s for use with polyval to produce error estimates on predictions.