数值分析实验一、95页第17题已知实验数据如下:用最小二乘法求一个形如的经验公式,使它拟合下列数据,并计算均方误差. 解:本题给出拟合曲线,即,故法方程系数法方程为解得最小二乘拟合曲线为均方程为二、238页第2题第二问求方程在=1.5附近的一个根解:设将方程改写为建立迭代公式,k=0,1,2,3…取,则原方程的根为=1.4665572三、书238页第7题第一问1.用牛顿法求在=2附近的根解:Newton 迭代法取,则,取2.用牛顿法求 的实根解:令,则,取四、49页第20 题 X j 0.25 0.30 0.39 0.45 0.53 Y j0.50000.54770.62450.67080.7280试求三次样条插值,并满足条件:(1)(0.25) 1.0000,(0.53)0.6868;(2)(0.25)(0.53)0.S S S S ''==''''==解:0101212323430.050.090.060.08h x x h x x h x x h x x =-==-==-==-=1111234,533,,,11457j j j j j jj jh h h h h h μλμμμμ---==--∴====[][][][]1230100110122334924,,,11457()(),0.9540,0.8533,0.7717,0.7150f x f x f x x x x f x x f x x f x x λλλλ====-==-===[][][][][][][][]040120012011012312212342332344343(1)() 1.0000,()0.68686(,) 5.5200,,6 4.3157,,6 3.2640,,6 2.43006(,) 2.1150S x S x d f x x f h f x x f x x d h h f x x f x x d h h f x x f x x d h h d f f x x h ''=='=-=--==-+-==-+-==-+'=-=- 由此得矩阵形式的方程组为2 1 M 0 5.5200-514 2 914M 1 4.3157- 35 2 25M 2 = 3.2640-37 2 47M 3 2.4300-1 2 M 4 2.1150-求解此方程组得012342.0278, 1.46431.0313,0.8070,0.6539M M M M M =-=-=-=-=-三次样条表达式为331122111()()()66()()(0,1,,1)66j j j j jj j jj j jj j j jjx x x x S x M M h h M h x x M h x x y y j n h h +++++--=+--+-+-=-∴将01234,,,,M M M M M 代入得[][]3333336.7593(0.30) 4.8810(0.25)10.0169(0.30)10.9662(0.25)0.25,0.302.7117(0.39) 1.9098(0.30) 6.1075(0.39) 6.9544(0.30)0.30,0.39() 2.8647(0.45) 2.2422(0.39)10.4186(0.45x x x x x x x x x x S x x x x ----+-+-∈----+-+-∈=----+-[][]33)10.9662(0.39)0.39,0.451.6817(0.53) 1.3623(0.45)8.3958(0.53)9.1087(0.45)0.45,0.53x x x x x x x ⎧⎪⎪⎪⎪⎪⎪⎨+-⎪⎪∈⎪⎪----+-+-⎪∈⎪⎩04001234404(2)()0,()020, 4.3157, 3.26402.4300,20S x S x d f d d d d f λμ''''==''===-=-''=-====由此得矩阵开工的方程组为0412******* 4.3157322 3.264055 2.43003027M M M M M ==⎛⎫⎪-⎛⎫⎛⎫⎪ ⎪ ⎪ ⎪=- ⎪ ⎪ ⎪ ⎪ ⎪-⎪⎝⎭⎝⎭ ⎪⎪⎝⎭求解此方程组,得012340, 1.88090.8616, 1.0304,0M M M M M ==-=-=-=又三次样条表达式为331122111()()()66()()66j j j j jj j jj j jj j j jjx x x x S x M M h h M h x x M h x x y y h h +++++--=+--+-+-将01234,,,,M M M M M 代入得[][]333336.2697(0.25)10(0.3)10.9697(0.25)0.25,0.303.4831(0.39) 1.5956(0.3) 6.1138(0.39) 6.9518(0.30)0.30,0.39() 2.3933(0.45) 2.8622(0.39)10.4186(0.45)11.1903(0.39)0.3x x x x x x x x x S x x x x x x --+-+-∈----+-+-∈∴=----+-+-∈[][]39,0.452.1467(0.53)8.3987(0.53)9.1(0.45)0.45,0.53x x x x ⎧⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪--+-+-⎪∈⎪⎩五、50页计算实习题第一题①/*拉格朗日差值*/ #include<stdio.h> #include<conio.h> #define N 4 void main(){int checkvalid(double x[],int n);double Largrange(double x[],double y[],double varx,int n); double x[N+1]={0.4,0.55,0.8,0.9,1};double y[N+1]={0.41075,0.57815,0.88811,1.02652,1.17520}; double varx=0.5;if(checkvalid(x,N)==1)printf("\n\n 插值结果:P(%f)=%f\n",varx,Largrange(x,y,varx,N)); elseprintf("输入的插值节点的x 值必须互异!"); getch(); }int checkvalid(double x[],int n) {int i,j;for(i=0;i<n+1;i++) for(j=i+1;j<n+1;j++) if(x[i]==x[j])return -1;elsereturn 1;}double Largrange(double x[],double y[],double varx,int n) {int k,j;double A,B,C=1,D=0;for(k=0;k<=n;k++){C=1;for(j=0;j<=n;j++){if(j!=k){A=(varx-x[j]);B=(x[k]-x[j]);C=C*A/B;}}D=D+C*y[k];}return D;}②/*牛顿插值*/#include<stdio.h>#include<conio.h>#define N 4int checkvalid(double x[],int n){int i,j;for(i=0;i<N;i++)for(j=i+1;j<=N;j++){if(x[i]==x[j])return(-1);}return(1);}void chashang(double x[N],double y[N],double f[N][N]){int i,j,h;for(j=0;j<=N;j++){f[j][j]=y[j];}for(h=1;h<=N;h++){for(i=0;i<=N-h;i++){f[i][i+h]=(f[i+1][i+h]-f[i][i+h-1])/(x[i+h]-x[i]);}}}double compvalue(double f[N][N],double x[N],double y[N],double varx) {int i;double t=1.000000,n=y[0];chashang(x,y,f);for(i=1;i<=N;i++){t=t*(varx-x[i-1]);n=n+f[0][i]*t;}return n;printf("the result is %f.",n);}void main(){int i,j;double varx,x[N],y[N],f[N][N];printf("input the value of x:");for(i=0;i<N;i++)scanf("%f",&x[i]);if(checkvalid(x,N)==1){printf("input the value of y:"); for(j=0;j<N;j++) scanf("%f",&y[j]);printf("input the value of varx:"); scanf("%f",&varx); compvalue(f,x,y,varx); } elseprintf("the value of x must be different!\n"); }六、238页第8题用牛顿迭代法求tan 0x x -=的最小正根.解 显然*0x =满足tan 0x x -=.另外当||x 较小时,2131tan ......321k x x x x k +=+++++,故当(0,)2x π∈时,tan x x >,因此,方程tan 0x x -=的最小正根应在3(,)22ππ内.记3()tan ,(,)22f x x x x ππ=-∈,容易算得(4) 2.842...0,(4.6) 4.26...0f f =>=-<,因此[4,4.6]是()0f x =的有限区间. 对于二分法,计算结果见下表此时391011|*|1021024x x --<=<.若用牛顿迭代法求解,由于221'()(tan )0,''()2tan 0cos f x x f x xx =-<=-<,故取0 4.6x =,迭代计算结果如表7-13所示.所以tan 0x x -=的最小正根为* 4.493409458x ≈.。