#include <iostream>
using namespace std;
void main()
{
float x,e,result;
float f(float x);
float romberg(float (*f)(float),float x,float e);
cout<<"输入自变量值:";
cin>>x;
cout<<"输入精度:";
cin>>e;
result=romberg(f,x,e);
cout<<"运算结果是:"<<result<<endl;
}
float romberg(float (*f)(float),float x,float e) [url=file://适/]file://适[/url]合于比较光滑的曲线求积
{
float t1,t2,h=1.0;
float g3(float x,float h);
for(t2=g3(x,h),t1=t2-e;t1-t2>=e || t2-t1>=e;h/=2)
t1=t2,t2=g3(x,h);
return t2;
}
/********************************************/ [url=file://加/]file://加[/url]速公式
float g3(float x,float h)
{
float g2(float x,float h);
return (64*g2(x,h/2)-g2(x,h))/63;
}
float g2(float x,float h)
{
float g1(float x,float h);
return (16*g1(x,h/2)-g1(x,h))/15;
}
float g1(float x,float h)
{
float g(float x,float h);
return (4*g(x,h/2)-g(x,h))/3;
}
float g(float x,float h)
{
float f(float x);
return (f(x+h)-f(x-h))/2/h;
}
/**********************************************/
float f(float x)
{
return x*x;
}