Which is the best degree of the polynomial?

2 ビュー (過去 30 日間)
Sakusan Puwanendran
Sakusan Puwanendran 2017 年 11 月 22 日
コメント済み: Sakusan Puwanendran 2017 年 11 月 22 日
I have to find an equation that models the velocity with time with the data given. I believe the fourth degree is the ideal one. Can someone confirm that please? Also, is the basic fitting and the polyfit function the same thing? The data is
T = table([0;10;15;20;32;59;62;125],[0;56.40;97.23;136.25;226.16;403.86;440.44;1265.23]);
T.Properties.VariableNames = {'Time' 'Velocity'};
v=T.Velocity;
t=T.Time;

採用された回答

Image Analyst
Image Analyst 2017 年 11 月 22 日
I think orders 2 and 3 fit better.
T = table([0;10;15;20;32;59;62;125],[0;56.40;97.23;136.25;226.16;403.86;440.44;1265.23]);
T.Properties.VariableNames = {'Time' 'Velocity'}
v=T.Velocity;
t=T.Time;
plot(t, v, 'b*-', 'LineWidth', 3, 'MarkerSize', 18);
grid on;
tFit = linspace(min(t), max(t), 500);
hold on;
for order = 1 : 4
coefficients = polyfit(t, v, order);
vFit = polyval(coefficients, tFit);
plot(tFit, vFit, '-', 'LineWidth', 1);
end
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
You don't want to do over fitting. It can lead to really bad values in between the training points. Look how much the 4th order curve varies from "reasonable" between 90 and 110.
  1 件のコメント
Sakusan Puwanendran
Sakusan Puwanendran 2017 年 11 月 22 日
I get a similar shape as yours for the 4th degree when using the basic fitting function on the graph figure however when I use the polyfit function I get a different function. Could you explain what I'm doing wrong? My code for polyfitting
p4 = polyfit(t,v,4) %4th DEGREE POLYNOMIAL FITTING
f4 = polyval(p4,t);
plot(t,v,t,f4)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by