c语言版本复合梯形法、辛普森法求积公式

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

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

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

资源描述

复合梯形法求积公式(f(x)=sinx/x)#includestdio.h#includemath.hvoidmain(){intk;doublea,b,n,h,x;doublef,f1,f2,T,F=0.0;printf(请输入abn:);scanf(%lf%lf%lf,&a,&b,&n);h=(b-a)/n;for(k=1;kn;k++){x=a+k*h;f=sin(x)/x;printf(\nf=%0.7f,f);F+=f;printf(\nF=%0.7f,F);}if(a!=0.0)f1=sin(a)/a;else(f1=1.0);printf(\nf1=%0.7f,f1);f2=sin(b)/b;printf(\nf2=%0.7f,f2);T=0.5*h*(f1+2*F+f2);printf(\nT=%0.7f,T);}复合辛普森公式(f(x)=sinx/x)#includestdio.h#includemath.hvoidmain(){intk;doublea,b,n,h;doublex,f,f1,f2,F1=0.0,F2=0.0,S=0.0;printf(请输入abn:);scanf(%lf%lf%lf,&a,&b,&n);h=(b-a)/n;for(k=0;kn;k++){x=a+k*h+0.5*h;f=sin(x)/x;printf(\nf=%0.7f,f);F1+=f;printf(\nF1=%0.7f,F1);}for(k=1;kn;k++){f=0;x=a+k*h;f=sin(x)/x;printf(\nf=%0.7f,f);F2+=f;printf(\nF2=%0.7f,F2);}if(a!=0)f1=sin(a)/a;else(f1=1.0);f2=sin(b)/b;S=h/6.0*(f1+4*F1+2*F2+f2);printf(\nS=%0.7f,S);}

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

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

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

×
保存成功