シンプソンの公式を使って円周率を計算
public double func(double x)
{
f = Math.sqrt(1 - x * x); //円の方程式
return f;
}
void button1_MouseClicked(java.awt.event.MouseEvent event)
{
a = 0; //原点
b = 1; //半径 1
h = (b - a) / (2 * n); //2n
等分する
x1 = a;
s = 0;
for(i = 0;i<=n-2 ;i++) //面積を合計する
{
x2 = x1 + h;
x3 = x2 + h;
s = s + (func(x1) + 4 *
func(x2) + func(x3)) * h / 3; //シンプソンの公式
x1 = x3;
}
label1.setText(" "+4*s); //4倍して面積を求める
}