In which order does polyfit command display coefficients?

19 ビュー (過去 30 日間)
Nick Krebbers
Nick Krebbers 2019 年 4 月 16 日
編集済み: Steven Lord 2019 年 4 月 16 日
Hello everyone,
I have a question that arose when reading the polyfit explanation. It says: "p = polyfit(x,y,n) returns the coefficients for a polynomial p(x) of degree n that is a best fit for the data in y. The coefficients in p are in descending powers".
The following example (from the same small article), however, shows that the coefficients are ascending from p1 to pn:
p(x)=p1*xn+p2*xn1+...+pn*x+pn+1.".
I am confused. If my polyfit output for a first degree polynomial is 1.33 and -4.5, in which order would they appear in the corresponding equation?
Thank you!
[SL: edited to remove some extraneous hyperlinks]

採用された回答

Star Strider
Star Strider 2019 年 4 月 16 日
The 1.33 value is the slope, and the -4.5 value is the intercept, so they would appear as [1.33 -4.5]. , corresponding to and respectively.
I interpret the coefficients as:
  2 件のコメント
Nick Krebbers
Nick Krebbers 2019 年 4 月 16 日
Thank you! So basically we insert them in the equation in the same order as they appear in the output, from leftmost to rightmost.
Star Strider
Star Strider 2019 年 4 月 16 日
As always, my pleasure!
That is how I would do it, with ‘leftmost’ being the coefficient of the highest-order of the polynomial, and ‘rightmost’ being the constant (intercept) term. The polyval function interprets them this way, so it automatically produces the correct result.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by