//======================================================
// Numerical Analysis package in java
// Gauss-Legendre integration utilizing
// 3 terms
// Dr. Turhan Coban
// =====================================================
import java.io.*;


class f1 extends f_x
{
  public double func(double x)
  {return -0.78277*x/(Math.exp(-x)-1);}
}

class integ8A
{
public static double integral(f_x f_xnt,double a,double b)
{
//integral f(x)dx
//integral of a function by using gauss-legendre quadrature
//coefficients are pre-calculated for 18 terms for [-1,1]
//band then utilises variable transform
// f_xnt integrating function
// a,b integral limits
 double r[],c[];
 r=new double[3];
 c=new double[3];
 r[0]=-0.774596669241483;
 r[1]=0.0;
 r[2]=0.774596669241483;

 c[0]=0.555555555555552;
 c[1]=0.888888888888888;
 c[2]=0.555555555555552;

int n=r.length;
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;
}
return z;
}

  public static void main(String args[]) throws IOException
  {
  //Romberg integrali
  f1 b1=new f1();
  System.out.println("integral of class         f1 : "+integral(b1,0.0,1.0));
}
}
