| Statistics Toolbox | Search  Help Desk |
| polyfit | Examples See Also |
Syntax
[p,S] = polyfit(x,y,n)
Description
p = polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) to y(i), in a least-squares sense. The result p is a row vector of length n+1 containing the polynomial coefficients in descending powers.
(x,y,n) returns polynomial coefficients p, and matrix, S for use with polyval to produce error estimates on predictions. If the errors in the data, y, are independent normal with constant variance, polyval will produce error bounds which contain at least 50% of the predictions.
You may omit S if you are not going to pass it to polyval or polyconf for calculating error estimates.
Example
[p,S] = polyfit(1:10,[1:10] + normrnd(0,1,1,10),1)
p =
1.0300 0.4561
S =
-19.6214 -2.8031
0 -1.4639
8.0000 0
2.3180 0
See Also
polyval,polytool,polyconf
polyfit is a function in MATLAB.