polyfit内部(见:type polyfit)实际用QR分解解一个系数矩阵为Vandermonde矩阵的方程,由于x的值很大,导致该矩阵的条件数很大(输入:cond(vander(x))可求出条件数,相当大啊),说明方程组的病态程度严重,Matlab不能保证求解精度,所以警告,并提示对数据进行缩放和集中,Matlab给出的方法(见:help polyfit)是:
再运行
完整程序如下:
x = [34560 35210 35860 38660 41000 41650 42670 44250];
y = [14.627 14.784 14.822 15.052 15.285 15.183 15.275 15.175];
x = (x - mean(x))/std(x);
p = polyfit(x,y,2)
xx = linspace(x(1),x(8));
yy = polyval(p,(xx - mean(x))/std(x));
plot(x,y,'o',xx,yy)
再运行
完整程序如下:
x = [34560 35210 35860 38660 41000 41650 42670 44250];
y = [14.627 14.784 14.822 15.052 15.285 15.183 15.275 15.175];
x = (x - mean(x))/std(x);
p = polyfit(x,y,2)
xx = linspace(x(1),x(8));
yy = polyval(p,(xx - mean(x))/std(x));
plot(x,y,'o',xx,yy)