//======================================================
// Numerical Analysis package in java
// Newton-Cotes integral formula 6 points, n=5
//
// 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 integ2
{

public static double newton_cotes6(f_x ff,double a,double b, int n)
{       //Newton-cotes integral 6 points, n=5
        // ff integrating function
        // a,b integral limits
        // n : number of sub division h=(b-a)/n;	
	    double h=(b-a)/n;
        double h1=h/5.0;
        double sum=0;
        int p,i;
        double x[]=new double[6];
        double f[]=new double[6];
        for(p=0;p<n;p++)
        {  {for(i=0;i<6;i++) {x[i]=a+i*h1+p*h;f[i]=ff.func(x[i]);}}
           sum+=h*(19.0*f[0]+75.0*f[1]+50.0*f[2]+50.0*f[3]+75.0*f[4]+19.0*f[5])/288.0; 
        }
        return sum;
}

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