资源描述:
《数值计算方法实习报告》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、数值计算方法实习报告学院:电气信息工程学院班级:电气xxxx学号:xxxxxxxxxxxx姓名:xxxxxxxxxx1、试用快速弦截法求此根,要求精确到小数点后第3位。#include#include#definePI3.1415floatf(floatx){floaty;y=x-cos(x);return(y);}main(){floatx0=0,x1=PI/2,e=0.001,f0,f1,x2,f2;clrscr();f0=f(x0);f1=f(x1);while(fabs(f1)>e){x2=x1-(x1-x0)*f1/(f1-f0);f2=f(x2
2、);x0=x1;x1=x2;f0=f1;f1=f2;}printf("%f",x2);}运行结果:0.7395672、设,,用Gauss-Jordan消元法求方程组的解。、#include#includemain(){floata[4][4]={0,0,0,0,0,3,1,1,0,2,2.0/3,1.0/3,0,1,2,-1},b[4]={0,8,5,-2},s,t,max;inti,j,l,k;clrscr();for(k=1;k<=3;k++){max=fabs(a[k][k]);l=k;for(i=k;i<=3;i++)if(fabs(a[i][k]
3、)>max){max=fabs(a[i][k]);l=i;}if(a[l][k]==0){printf("qiyijuzhen.");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
4、++)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]);}运行结果:x1=3.000000X2=-2.000000X3=1.0000003、已知函数表xi0.561600.562600.563600.56460yi0.827410.826590.825770.82495试用牛顿插值法求时的函数值。#includemain(){floatx[4]={0.56160,0.56260,0.56360,0.56460},y[4
5、]={0.82741,0.82659,0.82577,0.82495},z[4],u,v;inti,j,n=3;clrscr();for(i=0;i<=n;i++)z[i]=y[i];for(i=1;i<=n;i++){for(j=i;j<=n;j++)y[i]=(z[j]-z[j-1])/(x[j]-x[j-i]);for(j=i;j<=n;j++)z[j]=y[j];}printf("Inputchazhiu");scanf("%f",&u);v=0;for(i=n;i>=0;i--)v=v*(u-x[i])+y[i];printf("u=%f,v=%f",u,v);}运行结果:输
6、入:0,5635输出:u=0.563500,v=0.8258514、用龙贝格方法求积分,要求误差不超过。#include#includemain(){floatf(floatx);intk,j,n,d,i;floata,b,e,h,c,m,T[100],s;clrscr();printf("inputa,bande");scanf("a=%f,b=%f,e=%f",&a,&b,&e);k=0;n=1;h=b-a;T[0]=h/2*(f(a)+f(b));c=T[0];k=k+1;m=0;for(i=1;i<=n;i++)m=m+f(a+(i-1.0/2
7、)*h);T[k]=1.0/2*(T[k-1]+h*m);d=1;for(j=k;j>=1;j--){d=4*d;T[j-1]=T[j]+(T[j]-T[j-1])/(d-1);}while(fabs(c-T[0])>e){n=2*n;h=h/2;c=T[0];k=k+1;m=0;for(i=1;i<=n;i++)m=m+f(a+(i-1.0/2)*h);T[k]=1.0/2*(T[k-1]+h*m);d=1;}s=2.