资源描述:
《数值计算方法上机实习报告new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实习报告课程名称:数值计算方法上机学院:电气信息工程学院姓名:李勇学号:31005010632011年12月30日数值计算方法上机习题1.用Newton迭代法求解方程在2.0附近的实根,。源程序:#include#includemain(){doublex,f,f1;scanf("%lf",&x);for(;;x=x-f/f1){f=xxx-3x-1;f1=3xx-3;if(fabs(f)<0.5e-5)break;}printf("r=%lf",x);getch();r
2、eturn0;}输入:2.0运行结果:r=1.8793852.设(1)(2)试用高斯-约旦消去法求方程组的解。(1)源程序:#include#includemain(){floata[5][5]={0,0,0,0,0,0,5,7,9,10,0,6,8,10,9,0,7,10,8,7,0,5,7,6,5},b[5]={0,1,1,1,1},s,t,am;inti,j,l,k;clrscr();for(k=1;k<=4;k++){am=fabs(a[k][k]);l=k;for(
3、i=k;i<=4;i++)if(fabs(a[i][k])>am){am=fabs(a[i][k]);l=i;}if(a[l][k]==0){printf("qiyijuzhen.");break;}if(l!=k){for(j=k;j<=4;j++){t=a[k][j];a[k][j]=a[l][j];a[l][j]=t;}s=b[l];b[l]=b[k];b[k]=s;}for(j=k+1;j<=4;j++)a[k][j]=a[k][j]/a[k][k];b[k]=b[k]/a[k][k];for(i=1
4、;i<=4;i++){if(i==k)continue;b[i]=b[i]-a[i][k]b[k];for(j=k+1;j<=4;j++)a[i][j]=a[i][j]-a[i][k]a[k][j];}}printf("x1=%f",b[1]);printf("x2=%f",b[2]);printf("x3=%f",b[3]);printf("x4=%f",b[4]);}运行结果:x1=19.999809x2=-11.999882x3=-4.999953x4=2.999972(1)源程序:#i
5、nclude#includemain(){floata[4][4]={0,0,0,0,0,2,1,-3,0,3,6,2,0,4,5,-3},b[4]={0,-5,9,5},s,t,am;inti,j,l,k;clrscr();for(k=1;k<=3;k++){am=fabs(a[k][k]);l=k;for(i=k;i<=3;i++)if(fabs(a[i][k])>am){am=fabs(a[i][k]);l=i;}if(a[l][k]==0){printf("qiyij
6、uzhen.");break;}if(l!=k){for(j=k;j<=3;j++){t=a[k][j];a[k][j]=a[l][j];a[l][j]=t;}s=b[l];b[l]=b[k];b[k]=s;}for(j=k+1;j<=3;j++)a[k][j]=a[k][j]/a[k][k];b[k]=b[k]/a[k][k];for(i=1;i<=3;i++){if(i==k)continue;b[i]=b[i]-a[i][k]b[k];for(j=k+1;j<=3;j++)a[i][j]=a[i][j]
7、-a[i][k]a[k][j];}}printf("x1=%f",b[1]);printf("x2=%f",b[2]);printf("x3=%f",b[3]);}运行结果:x1=-11.000001x2=8.000000x3=-3.0000003.已知函数的数表xi0.320.340.360.38Sinxi0.31456660.33348710.35227420.3709205试用拉格朗日插值法求时的函数值。源程序:#includevoidmain(){floatx[4]={0
8、.32,0.34,0.36,0.38},y[4]={0.3145666,0.3334871,0.3522742,0.3709205};floatu,v,l;inti,j;clrscr();scanf("%f",&u);v=0;for(j=0;j<=3;j++){l=1;for(i=0;i<=3;i++){if(i==j)continue;l=l(u-x[i])/(x[j]-x[i]);}v=v+ly