simpson公式求定积分

double F(double x)
{
    
}
/// simpson求定积分
double simpson(double a,double b,double tk,double ta,double tb)
{
    double c=a+(b-a)/2;
    return (F(a)+4*F(c)+F(b))*(b-a)/6;
}

double asr(double a,double b,double EPS,double A)
{
    double c=a+(b-a)/2;
    double L=simpson(a,c),R=simpson(c,b);
    if(fabs(L+R-A)<=15*EPS) return L+R+(L+R-A)/15.0;
    return asr(a,c,EPS/2,L)+asr(c,b,EPS/2,R);
}

double asr(double a,double b,double EPS)
{
    return asr(a,b,EPS,simpson(a,b));
}
View Code

 

posted @ 2016-03-28 15:04  __560  阅读(570)  评论(0编辑  收藏  举报