help polyfit
polyfit Fit polynomial to data.
P = polyfit(X,Y,N) finds the coefficients of a polynomial P(X) of
degree N that fits the data Y best in a least-squares sense. P is a
row vector of length N+1 containing the polynomial coefficients in
descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).
[P,S] = polyfit(X,Y,N) returns the polynomial coefficients P and a
structure S for use with POLYVAL to obtain error estimates for
predictions. S contains fields for the triangular factor (R) from a QR
decomposition of the Vandermonde matrix of X, the degrees of freedom
(df), and the norm of the residuals (normr). If the data Y are random,
an estimate of the covariance matrix of P is (Rinv*Rinv')*normr^2/df,
where Rinv is the inverse of R.
[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,