//======================================================
// Numerical Analysis package in java
// Gauss-Legendre integration utilizing
// user given terms, roots calculated by Legendre transform
// Dr. Turhan Coban
// =====================================================
import java.io.*;


class f1 extends f_x
{ double T;
  public f1(double Ti)
  {T=Ti;}
  public double elambda(double x)
  {
	  double a[]=new double[7];
       a[0]=0.212960231058786;
       a[1]=-0.024551915394715;
       a[2]=-0.046020861143760;
       a[3]= 0.036900263791299;
       a[4]=-0.006884067195772;
       a[5]= 0.000509666334742;
       a[6]=-0.000013446879874;
       double eps=a[0]+a[1]*x+a[2]*x*x+a[3]*x*x*x+
       a[4]*x*x*x*x+a[5]*x*x*x*x*x+a[6]*x*x*x*x*x*x;
  return eps;	  
  }
  public double func(double x)
  {double C1=3.742e8;
   double C2=1.439e4;
   double sigma=5.67051e-8;
   return elambda(x)*C1/(x*x*x*x*x)/(Math.exp(C2/(x*T))-1.0);
  }
} 
 
class f2 extends f_x
{ double T;
  public f2(double Ti)
  {T=Ti;}
  
  public double func(double x)
  {double C1=3.742e8;
   double C2=1.439e4;
   double sigma=5.67051e-8;
   return C1/(x*x*x*x*x)/(Math.exp(C2/(x*T))-1.0);
  }
}


class integ9
{

public static double[][] gauss_legendre_coefficients(double x1,double x2,int n)
{
	// calculates legendre gauss-coefficients as coefficients of the integral
	// for n terms
	// x1,x2 integral limits
	// n : number of roots
	double EPS=3.0e-15;
	int m,j,i;
	double z1,z,xm,xl,pp,p3,p2,p1;
    double a[][]=new double[2][n];
	m=(n+1)/2;
	xm=0.5*(x2+x1);
	xl=0.5*(x2-x1);
	for (i=1;i<=m;i++)  {
		z=Math.cos(Math.PI*((i-0.25)/(n+0.5)));
		do {
			p1=1.0;
			p2=0.0;
			for (j=1;j<=n;j++) {
				p3=p2;
				p2=p1;
				p1=((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j;
			}
			pp=n*(z*p1-p2)/(z*z-1.0);
			z1=z;
			z=z1-p1/pp;
		} while (Math.abs(z-z1) > EPS);
		a[0][i-1]=xm-xl*z;
		a[0][n-i]=xm+xl*z;
		a[1][i-1]=2.0*xl/((1.0-z*z)*pp*pp);
		a[1][n-i]=a[1][i-1];
			}
return a;
}

public static double integral(f_x f_xnt,double x1,double x2,int n)
{return integral(f_xnt,x1,x2,n,false);}

public static double integral(f_x f_xnt,double x1,double x2,int n,boolean PRINT)
{
double a[][]=new double[2][n];
a=gauss_legendre_coefficients(x1,x2,n);
if(PRINT) Text.print(Text.T(a),"Gauss-Legendre coefficints n="+n);
double z=0;
for(int i=0;i<n;i++)
{ z+=a[1][i]*f_xnt.func(a[0][i]);}
return z;
}

  public static void main(String args[]) throws IOException
  {
  double T=1400.0;
  f1 b1=new f1(T);
  f2 b2=new f2(T);
  double e=integral(b1,0.3,13.0,40,false)/integral(b2,0.3,13.0,40,false);
  System.out.println("sonuc : "+e);
}
}
