1
25
2010
0

数值积分算法Simpson

http://en.wikipedia.org/wiki/Adaptive_Simpson%27s_method

 

double simpson_rec( double a, double b, double S, double fa, double fb, double fc,
		int bottom, double epsilon){
	double c = (a+b)/2, h = b-a;
	double d = (a+c)/2, e = (c+b)/2;
	double fd = f(d), fe = f(e);
	double SL = (h/12)*(fa + 4*fd+fc);
	double SR = (h/12)*(fc + 4*fe+fb);
	double S2 = SL + SR;
	if( bottom <= 0 || fabs(S2 - S ) <= 15*epsilon){
		return S2 + (S2-S)/15;
	}
	return 	simpson_rec(a,c,SL,fa,fc,fd, bottom-1, epsilon/2) + 
		simpson_rec(c,b,SR,fc,fb,fe, bottom-1, epsilon/2);
}

double simpson( double a, double b, double epsilon, int rec){
	double c = (a+b)/2, h = b-a;
	double fa = f(a);
	double fb = f(b);
	double fc = f(c);
	double S = (h/6) * (fa+4*fc+fb);
	return simpson_rec(a,b,S,fa,fb,fc,rec,epsilon);
}

 

 

Category: 未分类 | Tags: | Read Count: 703

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com