各位高手,谁知道怎么把这两个相互对应的数组的曲线给我拟合出来.我采用了最小二乘法但是好象不对,谁知道帮忙给我拟合一下,用C/C++都可以!很急知道帮忙一下~~~小弟感激不尽.写好了,可以发到我的邮箱:duan.gexin@byd.com.cn
double X[21] = {0.00,0.056,0.112,0.168,0.224,0.280,0.336,0.392,0.448,0.504,0.560, 0.616,0.672,0.728,0.784,0.84,0.896,0.952,0.1008,0.1064,1.12}
double Y[21] = {0.00,1.66,3.31,4.96,6.6,8.22,9.82,11.4,12.94,14.43,15.86,17.22,18.5, 19.69,20.79,21.79,22.71,23.53,24.25,24.87,25.4};谢谢拉~~
參考答案:用Matlab呀最方便了,三条语句就行了
>>x=[0.00,0.056,0.112,0.168,0.224,0.280,0.336,0.392,0.448,0.504,0.560, 0.616,0.672,0.728,0.784,0.84,0.896,0.952,0.1008,0.1064,1.12]
>>y=[0.00,1.66,3.31,4.96,6.6,8.22,9.82,11.4,12.94,14.43,15.86,17.22,18.5, 19.69,20.79,21.79,22.71,23.53,24.25,24.87,25.4]
>>a=polyfit(x,y,20)
a =
1.0e+016 *
Columns 1 through 10
-0.0231 0.2258 -1.0255 2.8708 -5.5471 7.8513 -8.4296 7.0150 -4.5838 2.3680
Columns 11 through 20
-0.9691 0.3134 -0.0795 0.0157 -0.0023 0.0003 -0.0000 0.0000 -0.0000 0.0000
Column 21
-0.0000
a是多项式系数,按降幂排列
polyfit(x,y,n)--最小二乘法曲线拟合函数,x,y是数据点,n是拟合多项式的次数,可根据情况调整。一般N+1个数据点,用N次多项式来拟合