simpson法计算arctan(1)-即pi/4
对1/(1+x^2) 进行0到1的积分即使pi/4;
采用simpson方法
Func<double,double> func=(x)=>{ return 1/(1+ Math.Pow(x,2) ) ;};
var n = 1000;
double h = 1.0d / n;
double sumx = 0;
double sum = func(0.0);
for (int i = 1; i < n; i++)
{
sumx += h;
var factor = ((i % 2) == 1) ? 4 : 2;
//Console.WriteLine(i +":" + factor +"," + sumx);
sum +=factor * func(sumx);
}
sum += func(1);
var v = 4* (sum * h) / 3;
Console.WriteLine(v);