资源描述:
《曲线拟合_线性最小二乘法及其MATLAB程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、函数逼近与曲线拟合1曲线拟合的线性最小二乘法及其MATLAB程序例7.2.1给出一组数据点列入表7–2中,试用线性最小二乘法求拟合曲线,并用(7.2),(7.3)和(7.4)式估计其误差,作出拟合曲线.表7–2例7.2.1的一组数据xi-2.5-1.7-1.1-0.800.11.52.73.6yi-192.9-85.50-36.15-26.52-9.10-8.43-13.126.5068.04解(1)在MATLAB工作窗口输入程序>>x=[-2.5-1.7-1.1-0.800.11.52.73.6];y=[-192.9-85.50-36.15-26.52-
2、9.10-8.43-13.126.5068.04];plot(x,y,'r*'),legend('实验数据(xi,yi)')xlabel('x'),ylabel('y'),title('例7.2.1的数据点(xi,yi)的散点图')运行后屏幕显示数据的散点图(略).(3)编写下列MATLAB程序计算在处的函数值,即输入程序>>symsa1a2a3a4x=[-2.5-1.7-1.1-0.800.11.52.73.6];fi=a1.*x.^3+a2.*x.^2+a3.*x+a4运行后屏幕显示关于a1,a2,a3和a4的线性方程组fi=[-125/8*a1+25
3、/4*a2-5/2*a3+a4,-4913/1000*a1+289/100*a2-17/10*a3+a4,-1331/1000*a1+121/100*a2-11/10*a3+a4,-64/125*a1+16/25*a2-4/5*a3+a4,a4,1/1000*a1+1/100*a2+1/10*a3+a4,27/8*a1+9/4*a2+3/2*a3+a4,19683/1000*a1+729/100*a2+27/10*a3+a4,5832/125*a1+324/25*a2+18/5*a3+a4]编写构造误差平方和的MATLAB程序>>y=[-192.9-85.
4、50-36.15-26.52-9.10-8.43-13.126.5068.04];fi=[-125/8*a1+25/4*a2-5/2*a3+a4,-4913/1000*a1+289/100*a2-17/10*a3+a4,-1331/1000*a1+121/100*a2-11/10*a3+a4,-64/125*a1+16/25*a2-4/5*a3+a4,a4,1/1000*a1+1/100*a2+1/10*a3+a4,27/8*a1+9/4*a2+3/2*a3+a4,19683/1000*a1+729/100*a2+27/10*a3+a4,5832/125*
5、a1+324/25*a2+18/5*a3+a4];fy=fi-y;fy2=fy.^2;J=sum(fy.^2)运行后屏幕显示误差平方和如下J=(-125/8*a1+25/4*a2-5/2*a3+a4+1929/10)^2+(-4913/1000*a1+289/100*a2-17/10*a3+a4+171/2)^2+(-1331/1000*a1+121/100*a2-11/10*a3+a4+723/20)^2+(-64/125*a1+16/25*a2-4/5*a3+a4+663/25)^2+(a4+91/10)^2+(1/1000*a1+1/100*a2+1
6、/10*a3+a4+843/100)^2+(27/8*a1+9/4*a2+3/2*a3+a4+328/25)^2+(19683/1000*a1+729/100*a2+27/10*a3+a4-13/2)^2+(5832/125*a1+324/25*a2+18/5*a3+a4-1701/25)^2为求使达到最小,只需利用极值的必要条件115.函数逼近与曲线拟合,得到关于的线性方程组,这可以由下面的MATLAB程序完成,即输入程序>>symsa1a2a3a4J=(-125/8*a1+25/4*a2-5/2*a3+a4+1929/10)^2+(-4913/1000
7、*a1+289/100*a2-17/10*a3+a4...+171/2)^2+(-1331/1000*a1+121/100*a2-11/10*a3+a4+723/20)^2+(-64/125*a1+16/25*a2-4/5*a3+a4+663/25)^2+(a4+91/10)^2+(1/1000*a1+1/100*a2+1/10*a3+a4+843/100)^2+(27/8*a1+9/4*a2+3/2*a3+a4+328/25)^2+(19683/1000*a1+729/100*a2+27/10*a3+a4-13/2)^2+(5832/125*a1+324
8、/25*a2+18/5*a3+a4-1701/25)^2;Ja1=