double gauss_legendre(double(*f)(double),double a,double b)
{
const int n=10;
const double z[10]={-0.9739065285,-0.8650633677,-0.6794095683,
-0.4333953941,-0.1488743390,0.1488743390,
0.4333953941,0.6794095683,0.8650633677,
0.9739065285};
const double w[10]={0.0666713443,0.1494513492,0.2190863625,
0.2692667193,0.2955242247,0.2955242247,
0.2692667193,0.2190863625,0.1494513492,
0.0666713443};
double y,gg;
int i;
gg=0.0;
for(i=0;i<n;i++)
{
y=(z[i]*(b-a)+a+b)/2.0;
gg+=w[i]*(*f)((double)y);
}
return((double)((gg*(b-a)/2.0)));
}
[/code]
作者:山城棒棒儿
GMT+8, 2024-11-24 23:41 , Processed in 0.036136 second(s), 15 queries , Gzip On.
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.