自适应simpton积分模板



double f(double x){
	return b*sqrt(1-(x*x)/(a*a)); 
} 
double simpton(double a,double b){
	double c=(a)+(b-a)/2;
	return (f(a)+4*f(c)+f(b))*(b-a)/6;
}

double integral(double L,double R,double Eps){
	double mid=L+(R-L)/2;
	double ST=simpson(L,R),SL=simpson(L,mid),SR=simpson(mid,R);
	if (fabs(SL+SR-ST)<=15*Eps) return SL+SR+(SL+SR-ST)/15;
	
	return integral(L,mid,Eps/2)+integral(mid,R,Eps/2);
}

猜你喜欢

转载自blog.csdn.net/qq_36172410/article/details/90030073