資源描述:
《數(shù)值計算方法上機實習報告new》由會員上傳分享,免費在線閱讀,更多相關內容在教育資源-天天文庫。
1、實習報告課程名稱:數(shù)值計算方法上機學院:電氣信息工程學院姓名:李勇學號:31005010632011年12月30日數(shù)值計算方法上機習題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.已知函數(shù)的數(shù)表xi0.320.340.360.38Sinxi0.31456660.33348710.35227420.3709205試用拉格朗日插值法求時的函數(shù)值。源程序:#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