1实验名称:曲线拟合的最小二乘法实验目的了解曲线拟合的最小二乘法实验类型设计型实验环境WindowsXPTC实验内容相关知识:已知C[a,b]中函数f(x)的一组实验数据(xi,yi)(i=0,1,…,m),其中yi=f(xi)。设);,,1,0)((mnnjxj是C[a,b]上线性无关函数族。在)}(,),(),({10xxxspann中找函数f(x)曲线拟合的最小二乘解njjjxaxS0*)()(,其法方程(组)为:),,1,0(),(0nkdanjkjjk其中,miikijikjxxx0)()()(),(mikikiikdxxfxf0)()()(),(k=0,1,…,n特别是,求函数f(x)曲线拟合的线性最小二乘解baxxS)(*的计算公式为:miimiimiiimiimiimiixxmyxxyxb020200002)()1())(())((miimiimiimiimiiixxmyxyxma0202000)()1())(()1(数据结构:两个一维数组或一个二维数组算法设计:(略)实验用例:已知函数y=f(x)的一张表:x0102030405060708090y6867.166.465.664.661.861.060.860.460试验要求:利用曲线拟合的线性最小二乘法求被逼近函数f(x)在点x=55处的近似值,并画出实验数据和直线。编写代码:#includestdio.h#includestdlib.h#includegraphics.hdoubleqiuhe1(doublea[10][2],intp){inti;doubley;y=0;for(i=0;i10;i++)y=y+a[i][p];returny;}doubleqiuhe2(doublea[10][2],intp){inti;doubley=0;for(i=0;i10;i++)y=y+a[i][0]*a[i][p];returny;}doublenihe(doublea[10][2],doublex){doublea1,b,y;a1=(10*qiuhe2(a,1)-qiuhe1(a,0)*qiuhe1(a,1))/(10*qiuhe2(a,0)-qiuhe1(a,0)*qiuhe1(a,0));b=(qiuhe2(a,0)*qiuhe1(a,1)-qiuhe1(a,0)*qiuhe2(a,1))/(10*qiuhe2(a,0)-qiuhe1(a,0)*qiuhe1(a,0));y=a1*x+b;returny;}intmain(){doublea[10][2]={0,68,10,67.1,20,66.4,30,65.6,40,64.6,50,61.8,60,61.0,70,60.8,80,60.4,90,60};doublex,x1,q=1;charc[12];inti;longn;intarw[6]={515,235,520,240,515,245};intarw1[6]={315,45,320,40,325,45};intgdriver=IBM8514;intgmode=IBM8514HI;initgraph(&gdriver,&gmode,c:\\TC20\\BGI);cleardevice();printf(inputx:\n);scanf(%lf,&x);printf(%f\n,nihe(a,x));n=nihe(a,x)*1000000+1;c[0]='y';c[1]='=';c[4]='.';for(i=10;i1;i--){if(i!=4){c[i]=n%10+48;n=n/10;}}c[11]='\0';x1=x;setbkcolor(7);setcolor(14);setlinestyle(0,0,3);drawpoly(3,arw);drawpoly(3,arw1);line(120,240,520,240);line(320,40,320,440);x=0;setcolor(2);setlinestyle(0,0,1);line((0+320),(int)(240-nihe(a,0)*q),(90+320),(int)(240-nihe(a,90)*q));setcolor(3);outtextxy(320,30,Y);outtextxy(310,245,O);outtextxy(525,240,X);outtextxy((x1+330),((240-nihe(a,x1))-10),c);settextstyle(4,0,4);outtextxy(450,400,Nihe...);for(i=0;i=9;i++)putpixel((a[i][0]+320),(240-a[i][1]*q),11);setcolor(4);setlinestyle(1,0,1);line((x1+320),((240-nihe(a,x1)*q)-80),(x1+320),((240-nihe(a,x1)*q)+120));getch();closegraph();}实验结果(测试用例、实验结果)实验总结与心得通过本次实验,对曲线拟合的最小二乘法有了更深刻的了解!