//======================================================
// Numerical Analysis package in java
// simpson integration of two dimensional function
// and differentiation (derivative) functions
// two dimensional Simpson 1/3 integration
// (quadratic Newton-Cotes formula)
// Dr. Turhan Coban
// =====================================================
import java.io.*;

abstract class fdi
{
public double a,b;
public fdi(double ai,double bi)
{a=ai;b=bi;}
public fdi()
{a=0;b=1;}
public void setab(double ai,double bi)
{a=ai;b=bi;}	
abstract public  double c(double x);
abstract public  double d(double x);
abstract public  double f(double x[]); 
}

class f1 extends fdi 
{
  public f1(double ai,double bi)
  {super(ai,bi);}
  
  public double c(double x)
  {return 1.0;}
  
  public double d(double x)
  {return 1.5;}
  
  public double f(double x[]) 
  {
  //çözümü istenen fonksiyon	
  double ff;
  ff=Math.log(x[0]+2.0*x[1]);
  return ff; 
  }
}  


class NA77
{
	
public static double I(fdi f,int m,int n) 
{
//integral f(x)dx
//integral of a function by using simpson metod
double h=(f.b-f.a)/n;
double J1=0.0;
double J2=0.0;
double J3=0.0;
double x[]=new double[2];
double HX=0;
double K1,K2,K3;
double d,c;
double Q,L,J;
for(int i=0;i<=n;i++)
{
x[0]=f.a+i*h;
d=f.d(x[0]);
c=f.c(x[0]);
HX=(d-c)/m;
x[1]=c;K1=f.f(x);
x[1]=d;K1+=f.f(x);
K2=0;
K3=0;
  for(int j=1;j<=(m-1);j++)
  {x[1]=f.c(x[0])+j*HX;
  Q=f.f(x);
  if((j/2)*2==j) K2=K2+Q;
  else           K3=K3+Q;
  }
L=(K1+2.0*K2+4.0*K3)*HX/3.0;
if((i==0)||(i==n)) J1=J1+L;
else if ((i/2)*2==i) J2=J2+L;
else J3=J3+L;  
}
J=h*(J1+2.0*J2+4.0*J3)/3.0;   
return J;
}



  public static void main(String args[]) throws IOException
  {
  f1 ff=new f1(1.4,2.0);	  
  System.out.println("integral of class         f1 : "+I(ff,20,20));
}
}
