polyfit
Polynomial curve fit by least squares.
Syntax
Section titled “Syntax”p = polyfit(x, y, n)[p, S, mu] = polyfit(x, y, n)Description
Section titled “Description”Fits a polynomial of degree n to the data (x, y) in a least-squares sense. Returns p, a row vector of coefficients in descending order of power. Optional S is a structure usable by polyval for confidence intervals. Optional mu = [mean(x), std(x)] returns the centering / scaling parameters used internally for numerical stability with high-degree fits.
Examples
Section titled “Examples”x = 1:10; y = 2*x + 3 + randn(1,10)*0.1;p = polyfit(x, y, 1) % approximately [2 3]