Statistics Toolbox | ![]() ![]() |
Syntax
Description
finds the coefficients of a polynomial p = polyfit(x,y,n)
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.
[p,S] = polyfit
returns polynomial coefficients (x,y,n)
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.
The polyfit
function is part of the standard MATLAB language.
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
![]() | polyconf | polytool | ![]() |