Issues with polynomial fit

1 次查看(过去 30 天)
I have a problem coding the best fit for these data
D=[0.5 5 10 100 1000];
y1=[1.56 2.12 4.34 7.13 10.22];
y2=[1.3 2.08 4.1 6.45 12.93].';
Thois below is the output
The polynomial fit works well for large values but for small values of D (e.g 0.5, 5) which is x-axis in my case, its weird. Please suggest me some best fit for this data. I made this code but it is not efficient
D=[0.5 5 10 100 1000].';
y1=[1.56 2.12 4.34 7.13 10.22].';
y2=[1.3 2.08 4.1 6.45 12.93].';
figure();
p1 = polyfit(D,y1,1); x1 = 0.5:0.001:1000; z1 = polyval(p1,x1);
semilogx(D,y1,'ro','MarkerEdgeColor','r','MarkerFaceColor','r',...
'MarkerSize',6); hold on;
semilogx(x1,z1,'r-','MarkerEdgeColor','r','MarkerFaceColor','r',...
'MarkerSize',6); hold on;
p2 = polyfit(D,y2,1); x2 = 0.5:0.001:1000; z2 = polyval(p2,x2);
semilogx(D,y2,'ko','MarkerEdgeColor','k','MarkerFaceColor','k',...
'MarkerSize',6);
semilogx(x2,z2,'k','MarkerEdgeColor','k','MarkerFaceColor','k',...
'MarkerSize',6);
title('Test','FontSize',16);
axis([0.5 1000 0.0 14]);
xlabel('X','FontSize',16);
ylabel('Y','FontSize',16)

采纳的回答

Spencer Chen
Spencer Chen 2020-1-24
You are fitting an order-1 polynomial, i.e. linear, so it is a bad fit. Try higher orders. But it looks like a different function will fit your data better.
Blessings,
Spencer
  3 个评论
Walter Roberson
Walter Roberson 2020-1-27
"Linear" and "order 1 polynomial" are the same.
Valeria Alejandra
Valeria Alejandra 2024-9-19
You could try linear interpolation. It is literally "linear" but no "order-1 polynomial" haha, but it is not good for extrapolating data

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by