资源描述:
《《数值分析大作业》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、《数值分析》大作业四一、算法设计方案:复化梯形积分法,选取步长为1/500=0.002,迭代误差控制在E≤1.0e-10①复化梯形积分法:,截断误差为:。复化Simpson积分法,选取步长为1/50=0.02,迭代误差控制在E≤1.0e-10②Simpson积分法:,截断误差为:。③Guass积分法选用Gauss-Legendre求积公式:截断误差为:R=η∈(1,1)。选择9个节点:-0.9681602395,-0.8360311073,-0.6133714327,-0.3242534234,0,0.3242
2、534234,0.6133714327,0.8360311073,0.9681602395,对应的求积系数依次为:0.0812743884,0.1806481607,0.2606106964,0.3123470770,0.3302393550,0.3123470770,0.2606106964,0.1806481607,0.0812743884。二、程序源代码:#include#include#include#defineE1.0e-10/****定义函数g
3、和K*****/doubleg(doublea){doubleb;b=exp(4*a)+(exp(a+4)-exp(-a-4))/(a+4);returnb;}doubleK(doublea,doubleb){doublec;c=exp(a*b);returnc;}/******复化梯形法******/voidTixing(){doubleu[1001],x[1001],h,c[1001],e;inti,j,k;FILE*fp;fp=fopen("f:/result0.xls","w");h=1.0/1500;
4、for(i=0;i<3001;i++){x[i]=i*h-1;u[i]=g(x[i]);}for(k=0;k<100;k++){e=0;for(i=0;i<1001;i++){for(j=1,c[i]=0;j5、ak;}for(i=0;i<1001;i++)fprintf(fp,"%.12lf,%.12lf",x[i],u[i]);fclose(fp);}/******复化Simpson法******/voidsimpson(){doubleu[101],x[101],h,c[101],d[101],e;inti,j,k;FILE*fp;fp=fopen("f:/result1.xls","w");h=1.0/50;for(i=0;i<101;i++){x[i]=i*h-1;u[i]=g(x[i]);}for(k=
6、0;k<50;k++){e=0;for(i=0;i<101;i++){for(j=1,c[i]=0,d[i]=0;j<51;j++){c[i]+=K(x[i],x[2*j-1])*u[2*j-1];if(j<50)d[i]+=K(x[i],x[2*j])*u[2*j];}u[i]=g(x[i])-4*h/3*c[i]-2*h/3*d[i]-h/3*(K(x[i],x[0])*u[0]+K(x[i],x[M-1])*u[M-1]);e+=h*(exp(4*x[i])-u[i])*(exp(4*x[i])-u[i]
7、);}if(e<=E)break;}for(i=0;i<101;i++)fprintf(fp,"%.12lf,%.12lf",x[i],u[i]);fclose(fp);}/******Gauss积分法******/voidgauss(){doublex[9]={-0.9681602395,-0.8360311073,-0.6133714327,-0.3242534234,0, .3242534234,0.6133714327,0.8360311073,0.9681602395},A[9]={0.0812
8、743884,0.1806481607,0.2606106964,0.3123470770,0.3302393550, .3123470770,0.2606106964,0.1806481607,0.0812743884},u[9],c[9],e;inti,j,k;FILE*fp;fp=fopen("f:/result2.xls","w");for(i=0;i<9;i++)u[i]=