《用matlab中最小二乘法编程求解》由会员分享,可在线阅读,更多相关《用matlab中最小二乘法编程求解(2页珍藏版)》请在人人文库网上搜索。
1、有一组关于M、H的实验数据(附件1.data),已知其符合: 分布,请利用最小二乘法编写程序求三个参数a、b、c的值(要求:利用MATLAB编程)(20分)解:拟合两组数据M、H,已知 ,只需确定多项式系数a、b、c。根据最小二乘原则,使 所求问题成为三元一次函数S(a,b,c)的极小点问题。由多元函数取极值的必要条件知a,b,c比为, , 的解,即满足将三元一次线性方程组带入Matlab,其程序如下:clear M=-1.6087e+04,-1.3986e+04,-1.2029e+04,-1.0000e+04,-7.8986e+03,-6.0145e+03,-3.9855e+03,-2.02。
2、90e+03,-1.0145e+03,-4.3478e+02,0.0000,2.1739e+02,.7.9710e+02,2.0290e+03,4.2029e+03,6.0870e+03,8.0435e+03,1.0000e+04,1.2029e+04,1.4203e+04,1.6087e+04;H=-7.5164e+01,-7.5531e+01,-7.5548e+01,-7.4174e+01,-7.3844e+01,-7.0035e+01,-6.5878e+01,-6.0678e+01,-4.9209e+01,.-3.1822e+01,1.7391e-01,2.9042e+01,4.6080。
3、e+01,5.4069e+01,6.1355e+01,6.5512e+01,6.8626e+01,6.8261e+01,7.0330e+01,.7.0311e+01,7.0991e+01; sum(2*M.2),sum(2*M.4),sum(2*M.6),sum(2*M.8),sum(2*M.10),sum(2*M.*H),sum(2*M.3.*H),sum(2*M.5.*H)ans =3.2966e+009ans =5.7227e+017ans =1.1808e+026ans =2.6408e+034ans =6.1821e+042ans =2.0801e+007ans =3.0495e+015ans =5.9067e+023 a,b,c=solve(3.2966e+009*a+5.7227e+017*b+1.1808e+026*c=2.0801e+007,5.7227e+017*a+1.1808e+026*b+2.6408e+034*c=3.0495e+015,1.1808e+026*a+2.6408e+034*b+6.1821e+042*c= 5.9067e+023,a,b,c); a=double(a),b=double(b),c=double(c)a =0.0164b =-1.1080e-010c =2.5628e-019。