//======================================================
// 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_xj
{
public double func(double x[]) 
{
//çözümü istenen fonksiyon	
double ff;
ff=2.0*x[0]/((1.0+x[1])*(1.0+x[1]));
return ff; //minimum değil maxsimum istendiğinden - ile çarptık
}
}


class integ_monte_carlo2
{

public static double monte_carlo(f_xj ff,double a[],double b[], long n)
{       //monte - carlo integral 3D (volume)
	    double x[]=new double[2];
	    double h=1.0;
	    double sum=0;
	    for(int j=0;j<2;j++) {h*=(b[j]-a[j]);}
	    for(int i=0;i<n;i++)
        { for(int j=0;j<2;j++) {x[j]=a[j]+(b[j]-a[j])*Math.random();}
          sum+=ff.func(x); 
        }
        return h*sum/(double)n; 
}

  public static void main(String args[]) throws IOException
  {
  f1 b1=new f1();
  double a[]=new double[2];
  double b[]=new double[2];
  a[0]=0;
  a[1]=0;
  b[0]=1;
  b[1]=1;
  System.out.println("integral of class         f1 : "+monte_carlo(b1,a,b,100000));
}
}
