变步长复化一点高斯求积

来源:互联网 发布:电路模拟软件下载 编辑:程序博客网 时间:2024/05/16 09:18
#include <iostream>
using namespace std;
void main()
{
float a,b,e,result;
float f(float x);
float guass(float (*f)(float),float a,float b,float e);
cout<<"输入端点:";
cin>>a>>b;
cout<<"输入精度:";
cin>>e;
result=guass(f,a,b,e);
cout<<"运算结果是:"<<result;
}
float guass(float (*f)(float),float a,float b,float e) [url=file://适/]file://适[/url]合于比较光滑的曲线求积
{
float t1,t2,s,h,x;
h=(b-a)*2,t2=h*(f(a)+f(b))/2;
for(t1=t2-2*e;t2-t1>=e || t1-t2>=e;t2=h*s)  
  for(h/=2,t1=t2,s=0,x=a+h/2;x<b;x+=h)
   s+=f(x);  
return t2;
}
float f(float x)
{
return x*x;
}
原创粉丝点击