自适应辛普森积分

求一段区间函数与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);
*/

自适应辛普森积分

上一篇:直连组网直接转信道和协议的配置


下一篇:128. 最长连续序列