FUNCTION REFERENCE
polyfit
Fit a polynomial to data by least squares.
Fit a polynomial to data by least squares.
Syntax
p = polyfit(x, y, degree); [p,S] = polyfit(x,y,degree); [p,S,mu] = polyfit(x,y,degree)Returns a row of coefficients in descending powers. x and y must be finite real vectors of equal length; logical inputs convert to double. Degree must be an integer from 0 to 4096, and the fitting matrix must fit the statement limit. Underdetermined and rank-deficient systems use a basic solution with dependent coefficients set to zero.
Example
round(polyfit(1:5,[1 4 9 16 25],2)) % [1 -0 0]Differences from MATLAB: Ill-conditioned and rank-deficient coefficients can differ, and MATLAB's conditioning warnings are not printed. Underdetermined fits (fewer points than coefficients) work. For real inputs, S contains R (the unpivoted QR factor), df and normr. Three outputs center x by its mean and scale it by its sample standard deviation, returned in mu. Statistics require at least degree+1 points; normalization needs a positive finite scale. Complex multiple outputs are unsupported. Complex x or y is fitted by Householder QR of the Vandermonde matrix; the last digits can differ from MATLAB's MKL QR.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.