| //自适应梯形求积法 //a-积分下限
 //b-积分上限,要求b>a
 //eps-积分精度要求
 //d-对积分区间进行分割的最小步长,当子区间的宽度小于d时,
 //  即使没有满足精度要求,也不再往下进行分割
 //bbptsf-积分函数
 //调用函数 ppp()
 static void ppp(double x0,double x1,double h,double f0,double f1,double t0,double eps,double d,double t[],double (*bbptsf)(double));
 double bbpts(double a,double b,double eps,double d,double (*bbptsf)(double))
 {
 double h,t[2],f0,f1,t0,z;
 h=b-a;
 t[0]=0.0;
 f0=bbptsf(a);
 f1=bbptsf(b);
 t0=h*(f0+f1)/2.0;
 ppp(a,b,h,f0,f1,t0,eps,d,t,bbptsf);
 z=t[0];
 return(z);
 }
 static void ppp(double x0,double x1,double h,double f0,double f1,double t0,double eps,double d,double t[],double(*bbptsf)(double))
 {
 double x,f,t1,t2,p,g,eps1;
 x=x0+h/2.0;
 f=bbptsf(x);
 t1=h*(f0+f)/4.0;
 t2=h*(f+f1)/4.0;
 p=fabs(t0-(t1+t2));
 if ((p<eps)||(h/2.0<d))
 {
 t[0]=t[0]+(t1+t2);
 return;
 }
 else
 {
 g=h/2.0;
 eps1=eps/1.4;
 ppp(x0,x,g,f0,f,t1,eps1,d,t,bbptsf);
 ppp(x,x1,g,f,f1,t2,eps1,d,t,bbptsf);
 return;
 }
 }
 |