//======================================================
// Numerical Analysis package in java
// Newton-Cotes integral formula 9 points, n=8
//
// Dr. Turhan Coban
// =====================================================
import java.io.*;


class f1 extends f_x
{
  double func(double x)
  {
  return 4.0/Math.PI*Math.sqrt(1.0-x*x);
  }
}


class integ2A
{

public static double newton_cotes9(f_x ff,double a,double b, int n)
{       //Newton-cotes integral 9 points, n=8
        // ff integrating function
        // a,b integral limits
        // n : number of sub division h=(b-a)/n;
	    double h=(b-a)/n;
        double h1=h/8.0;
        double sum=0;
        int p,i;
        double x[]=new double[9];
        double f[]=new double[9];
        for(p=0;p<n;p++)
        {  {for(i=0;i<9;i++) {x[i]=a+i*h1+p*h;f[i]=ff.func(x[i]);}}
           sum+=h/28350.0*(989.0*f[0]+5888.0*f[1]-928.0*f[2]+10496.0*f[3]-4540.0*f[4]+
           10496.0*f[5]-928.0*f[6]+5888.0*f[7]+989.0*f[8]); 
        }
        return sum;
}

        public static void main(String args[]) throws IOException
        { f1 b1=new f1();
          double i1=  newton_cotes9(b1,0.0,1.0,10);
          double i2 = 1.0;
          double hata =i2-i1;
          System.out.println("integral of class         f1 : "+i1+" hata="+hata);
        }
}
