Given a set of date point x and y, estimate three polynomial functions (2nd degree, 3rd degree, 4th degree) that will best fit the data.

1 回表示 (過去 30 日間)
Given a set of date point x and y, estimate three polynomial functions (2nd degree, 3rd degree, 4th degree) that will best fit the data. Compute new set of y data from the three functions and determine which of the three functions will give the least norm difference.
This is what I've came up with, but still not sure if it really satisfy the problem.
x=[0.9 1.5 3 4 6 8 9.5];
y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3];
p=polyfit(x,y,3)
xp=0.9:0.1:9.5;
yp=polyval(p,xp);
plot(x,y,'o',xp,yp)
xlabel('x'); ylabel('y')

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 11 月 27 日
The question is expecting you to also polyfit with degree 2 and 4, and to polyval with those, and to compute the norm() of the projected values against the actual values, and then to see whether degree 2, degree 3, or degree 4 gave the best fit.
  2 件のコメント
John Doe
John Doe 2021 年 11 月 27 日
編集済み: John Doe 2021 年 11 月 27 日
Is it like this?
x = [0.9 1.5 3 4 6 8 9.5];
y = [0.9 1.5 2.5 5.1 4.5 4.9 6.3];
p = polyfit(x,y,2);
l = polyfit(x,y,3);
t = polyfit(x,y,4);
xp = 0.9:0.1:9.5;
yp1 = polyval(p,xp);
yp2 = polyval(l,xp);
yp3 = polyval(t,xp);
xlabel('x');
ylabel('y');
plot(x,y,'o',xp,yp1,yp2,yp3)
Walter Roberson
Walter Roberson 2021 年 11 月 27 日
x = [0.9 1.5 3 4 6 8 9.5];
y = [0.9 1.5 2.5 5.1 4.5 4.9 6.3];
p = polyfit(x,y,2);
l = polyfit(x,y,3);
t = polyfit(x,y,4);
xp = 0.9:0.1:9.5;
yp1 = polyval(p,xp);
yp2 = polyval(l,xp);
yp3 = polyval(t,xp);
xlabel('x');
ylabel('y');
plot(x,y,'o',xp,yp1,xp,yp2,xp,yp3)

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

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by