其他分享
首页 > 其他分享> > 自适应辛普森积分

自适应辛普森积分

作者:互联网

求一段区间函数与x轴的面积问题

const double eps = 1e-7;
double a,b,c,d,L,R;
double f(double x) {
	return (c*x+d)/(a*x+b);
}

double simpson(double l,double r) {
	return (f(l)+f(r)+4*f((l+r)/2))*(r-l)/6;
}

double asr(double l,double r,double ep,double val) {
	double mid = (l+r)/2;
	double lval = simpson(l,mid),rval=simpson(mid,r);
	if(fabs(lval+rval-val)<=15*ep) {
		return lval+rval+(lval+rval-val)/15;
	}
	return asr(l,mid,ep/2,lval)+asr(mid,r,ep/2,rval);
}

double asme(double l,double r,double ep) {
	return asr(l,r,ep,simpson(l,r));
}

void work() {
	scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R);
	printf("%lf\n",asme(L,R,eps));
}

/*
const double inf = 30,zero = 1e-9
double f(double x) {
	return pow(x,(a/x)-x);
}
double ans = asme(zero,inf,eps);
*/

标签:适应,val,积分,rval,mid,lval,辛普森,double,simpson
来源: https://www.cnblogs.com/LaiYiC/p/14992359.html