变步长,辛普森,梯形公式

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includemath.h#includestdio.h#includestdlib.h#includewindows.h#includeconio.h#defineESC27#defineEPS0.5e-7#definef(x1)(-2.0/(x1*x1-1))#defineg(x2)(-2.0/(x2*x2-1))#defines(x0)(-2.0/(x0*x0-1))chart;voidtixing(){doublea1=2,b1=3;doubleT,h1,x1;intn,i;printf(pleaseinputn:);scanf(%d,&n);h1=(b1-a1)/n;x1=a1;T=0;for(i=1;in;i++){x1+=h1;T+=f(x1);}T=(f(a1)+2*T+f(b1))*h1/2;printf(T(%d)=%g\n,n,T);printf(Theexactvalueis%g\n,log(2)-log(3));}voidSimpson(){doublea2=2,b2=3;doubleS,h2,x2;intm,j;printf(pleaseinputEvenm:);scanf(%d,&m);h2=(b2-a2)/m;x2=a2;S=0;for(j=1;jm;j++){x2+=h2;if(j%2==0)S+=2*g(x2);elseS+=4*f(x2);}S=(g(a2)+S+g(b2))*h2/3;printf(S(%d)=%g\n,m,S);printf(Theexactvalueis%g\n,log(2)-log(3));}voidBianbuc(){doublec=2,d=3;doubleT1,T2,h3,x0,sum;intq=1,k=1;h3=d-c;T2=(s(c)+s(d))/2;do{T1=T2;x0=c;h3/=2;q*=2;sum=0;for(k=1;kq;k+=2){x0=c+k*h3;sum+=s(x0);}T2=T1/2+sum*h3;printf(T(%d)\t=%12.8g\n,q,T2);}while(fabs(T2-T1)=EPS);printf(Theexactvalueis%12.8g\n,log(2)-log(3));}voidmain(){do{system(color1b);system(cls);printf(\n\t\t\t***************\t\t\t);printf(\n\t\t\t****实验四*****\t\t\t);printf(\n\t\t\t**1.梯形积分***\t\t\t);printf(\n\t\t\t**2.辛普森*****\t\t\t);printf(\n\t\t\t**3.变步长*****\t\t\t);printf(\n\t\t\t请选择1或2或ESC退出\n);printf(\t\t\t****************\t\t\t\n);t=getch();}while(t!='1'&&t!='2'&&t!='3'&&t!=ESC);while(t=='1'||t=='2'||t=='3'||t==ESC){if(t=='1'){system(cls);printf(pleasewaiting....\n);Sleep(1000);tixing();break;}if(t=='2'){system(cls);printf(pleasewaiting....\n);Sleep(1000);Simpson();break;}if(t=='3'){system(cls);printf(pleasewaiting....\n);Sleep(1000);Bianbuc();break;}if(t==ESC){printf(已经退出!\n);break;}}}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功