matlab数据拟合的问题
这是我的编程x=[1990:2005];y=[61627598909397100108160221268320382447504];plot(x,y,'y-')holdo...
这是我的编程
x=[1990:2005];
y=[61 62 75 98 90 93 97 100 108 160 221 268 320 382 447 504];
plot(x,y,'y-')
hold on
p=polyfit(x,y,1)
z=polyval(p,x);
plot(x,z,'b+')
hold on
p=polyfit(x,y,2)
z=polyval(p,x);
plot(x,z,'r--')
hold on
p=polyfit(x,y,3)
z=polyval(p,x);
plot(x,z,'k.')
hold on
p=polyfit(x,y,4)
z=polyval(p,x);
plot(x,z,'m*')
title('全国(1990年~2005年)历年参加高考人数和录取人数')
xlabel('年份')
ylabel('万人')
可是运行后的结果却是这样,怎么办
p =
1.0e+004 *
0.0028 -5.5937
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 9
p =
1.0e+007 *
0.0000 -0.0012 1.1802
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 13
p =
1.0e+008 *
0.0000 -0.0000 0.0134 -8.8835
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 17
p =
1.0e+011 *
-0.0000 0.0000 -0.0000 0.0133 -6.6357
好像P值无法精确给出,但是从图像来看的话,4次拟合多项式会更吻合一点
有没有什么办法可以给出P值呢?请叙述详细点,我刚学 展开
x=[1990:2005];
y=[61 62 75 98 90 93 97 100 108 160 221 268 320 382 447 504];
plot(x,y,'y-')
hold on
p=polyfit(x,y,1)
z=polyval(p,x);
plot(x,z,'b+')
hold on
p=polyfit(x,y,2)
z=polyval(p,x);
plot(x,z,'r--')
hold on
p=polyfit(x,y,3)
z=polyval(p,x);
plot(x,z,'k.')
hold on
p=polyfit(x,y,4)
z=polyval(p,x);
plot(x,z,'m*')
title('全国(1990年~2005年)历年参加高考人数和录取人数')
xlabel('年份')
ylabel('万人')
可是运行后的结果却是这样,怎么办
p =
1.0e+004 *
0.0028 -5.5937
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 9
p =
1.0e+007 *
0.0000 -0.0012 1.1802
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 13
p =
1.0e+008 *
0.0000 -0.0000 0.0134 -8.8835
Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.
> In polyfit at 79
In a100 at 17
p =
1.0e+011 *
-0.0000 0.0000 -0.0000 0.0133 -6.6357
好像P值无法精确给出,但是从图像来看的话,4次拟合多项式会更吻合一点
有没有什么办法可以给出P值呢?请叙述详细点,我刚学 展开
2个回答
展开全部
%x太大,以x的幂作为基函数会导致设计矩阵尺度太差,列变量几乎线性相依。
%变换为[-1 1]范围计算
x=[1990:2005];t=(x-2040)/50;
y=[61 62 75 98 90 93 97 100 108 160 221 268 320 382 447 504];
p1=polyfit(t,y,1); z1=polyval(p1,t);
p2=polyfit(t,y,2); z2=polyval(p2,t);
p3=polyfit(t,y,3); z3=polyval(p3,t);
p4=polyfit(t,y,4); z4=polyval(p4,t);
h=plot(t,y,'go',t,z1,'b+',t,z2,'r--',t,z3,'k.',t,z4,'m*');
xlabel('年份');ylabel('万人');
set(gca,'XTick',t,'XTickLabel',sprintf('%d|',x));
title('全国(1990年~2005年)历年参加高考人数和录取人数');
legend('data','1st poly','2nd poly','3rd poly','4th poly',2);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询