Return the coefficients of a polynomial p(x) of degree n that minimizes the least-squares-error of the fit.
The polynomial coefficients are returned in a row vector.
The second output is a structure containing the following fields:
- ‘R’
- Triangular factor R from the QR decomposition.
- ‘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.
The second output may be used by
polyval
to calculate the statistical error limits of the predicted values.When the third output, mu, is present the coefficients, p, are associated with a polynomial in xhat = (x-mu(1))/mu(2). Where mu(1) = mean (x), and mu(2) = std (x). This linear transformation of x improves the numerical stability of the fit.