//======================================================
// Numerical Analysis package in java
// Newton-Cotes integral formula 4 points , n=3
// Simpson 1/3 rule
// 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 integ5
{
public static double newton_cotes3(f_x ff,double a,double b, int n)
{       //Newton-cotes integral 3 points
        //Simpson 1/3 rule
	    // ff integrating function
        // a,b integral limits
        // n : number of sub division h=(b-a)/n;
        double h=(b-a)/n;
        double h1=h/2.0;
        double sum=0;
        int p,i;
        double x[]=new double[3];
        double f[]=new double[3];
        for(p=0;p<n;p++)
        {  {for(i=0;i<3;i++) {x[i]=a+i*h1+p*h;f[i]=ff.func(x[i]);}}
           sum+=h*(f[0]+4.0*f[1]+f[2])/6.0; 
        }
        return sum;
}

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