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


class f1 extends f_x
{
  public double func(double x)
  {
  double ff=4.0/(1+256*(x-0.375)*(x-0.375));
  return ff;
  }
}

class NAFP2
{
public static double integral(f_x f_xnt,double a,double b)
{
 double r[],c[];
 int n=4;
 r=new double[n];
 c=new double[n];
 r[ 0] = -0.861136311594052;
 r[ 1] = -0.339981043584856;
 r[ 2] = 0.339981043584856;
 r[ 3] = 0.861136311594052;
 c[ 0] = 0.347854845137447;
 c[ 1] = 0.652145154862546;
 c[ 2] = 0.652145154862546;
 c[ 3] = 0.347854845137447;
double z=0;
double x,y;
double k1=(b-a)/2.0;
double k2=(b+a)/2.0;
for(int i=0;i<n;i++)
{
x=k2+k1*r[i];
y=f_xnt.func(x);
z+=k1*c[i]*y;
System.out.println("k1="+k1+"k2="+k2+"x="+x+"y="+y+"z="+z);
}
return z;
}

  public static void main(String args[]) throws IOException
  {
  //Gauss-Legendre integration formula with n=10
  f1 b1=new f1();
  System.out.println("integral of class         f1 : "+integral(b1,0.0,1.0));
}
}
