//======================================================
// Numerical Analysis package in java
// example to show utilisation of integration (integral)
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import java.io.*;


class f1 extends f_x
{
  double func(double x)
  {
  return 2.0/(1.0+2.0*x*x);
  }
}


class integ2
{

public static double newton_cotes6(f_x ff,double a,double b, int n)
{       //Newton-cotes integral 6 points
	    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]);System.out.println("i="+i+" "+x[i]+" "+f[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();
  System.out.println("integral of class         f1 : "+
  newton_cotes6(b1,-3.0,3.0,100));
}
}
