#include <iostream>
using namespace std;
void main()
{
float a,b,e,result;
float f(float x);
float romberg(float (*f)(float),float a,float b,float e);
cout<<"输入端点:";
cin>>a>>b;
cout<<"输入精度:";
cin>>e;
result=romberg(f,a,b,e);
cout<<"运算结果是:"<<result;
}
float romberg(float (*f)(float),float a,float b,float e) [url=file://适/]file://适[/url]合于比较光滑的曲线求积
{
float t1,t2,s1,s2,c1,c2,r1=0,r2=e;
float s,h,x,k=1;
h=b-a,t1=h*(f(a)+f(b))/2;
while(r2-r1>=e || r1-r2>=e)
{
for(s=0,x=a+h/2;x<b;x+=h)
s+=f(x);
t2=(t1+h*s)/2;
s2=t2+(t2-t1)/3;
if(k==1)
{
k++,h/=2;
t1=t2,s1=s2;
continue;
}c2=s2+(s2-s1)/15;
if(k==2)
{
k++,h/=2;
t1=t2,s1=s2,c1=c2;
continue;
}r2=c2+(c2-c1)/63;
r1=r2,c1=c2;
t1=t2,s1=s2;
k++,h/=2;
}
return r2;
}
float f(float x)
{
return x*x;
}