computing a regression polynomial of degree 2

1 回表示 (過去 30 日間)
Anas Gharsa
Anas Gharsa 2022 年 1 月 26 日
コメント済み: Anas Gharsa 2022 年 1 月 26 日
I want to compute a regression polynomial for some datapoints and than estimate the value of the function at another datapoint!! i wrote something that gives me 0 error but the graph is not ok!! this is what i wrote
x= [0.9 1.5 2.4 2.6 2.8 3.1 3.5 3.8]; %Data points
y= [1.0 0.8 1.3 6.2 9.3 6.0 2.1 -0.5];
p1 = polyfit(x,y,2); %The regression polynomial of degree 2
yest = polyval(p1,2.5);
xfit = linspace(0,length(x),8);
yfit = polyval(p1,xfit);
plot(x,y,'o',xfit,yfit,'-');
hold on
p2 = polyfit(x,y,7); %The regression polynomial of degree 7
yest2 = polyval(p2,2.5);
xfit1 = linspace(0,10,8);
yFit1 = polyval (p2,2.5);
plot(x,y,'b',xfit1,yFit1,'--');
hold on
  4 件のコメント
Torsten
Torsten 2022 年 1 月 26 日
You didn't substitute xfit1=x.
Anas Gharsa
Anas Gharsa 2022 年 1 月 26 日
Thank you so much !!!

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by