Using polyfit for linear regression

62 ビュー (過去 30 日間)
agung pratama
agung pratama 2020 年 10 月 8 日
コメント済み: agung pratama 2020 年 10 月 8 日
Hi guys, how do i get linear regression (p) of this X1 and Y1 values using polyfit?
I try but the X1 and Y1 keep changes back, expected i get like this graph in help window
  2 件のコメント
KSSV
KSSV 2020 年 10 月 8 日
Try clear all and run the code.
agung pratama
agung pratama 2020 年 10 月 8 日
編集済み: agung pratama 2020 年 10 月 8 日
Im sorry but its not working,
Do you think the code must be change?

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

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 10 月 8 日
Your code looks OK. Your problem might be that you expect a result identical to the figure from the documentation.
However, you ask for a linear fit in your call to polyfit - note the difference between your call and the call in the documentation!
your call:
p = polyfit(x,y,1);
Call in documentation:
p = polyfit(x,y,7);
You ask for a first-order polynomial, the call from the documentation is for a 7-order polynomial. That's the difference.
HTH
  1 件のコメント
agung pratama
agung pratama 2020 年 10 月 8 日
Yes i do that in purpose,i want first-order polynomial, so i change the code. My problem is how i change x1 and y1 value to get new p.

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

カテゴリ

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