//Gauss-Chebychev integral
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class f1 extends f_x
{
  public double func(double x)
  {
  return Math.exp(x);
  }
}

public class NA62 
{
	    	
public static double[][] gauss_chebychev_coefficients(int n)
{   //Gauss-Chebychev quadratürü katsayılarını hesaplar
    double sgngam=1;     
    double a[][]=new double[2][n];
    for(int j = 1; j <=n; j++)
    {int k=j-1;    
     a[0][k]=Math.cos((2.0*j-1.0)*Math.PI/(2.0*n));
     a[1][k]=Math.PI/(double)n;
    }    
return a;
}

public static double gauss_chebychev_integral(f_x f_xnt,int n)
{
//n : number of integral coefficients
// this routine first generates gauss chebychev coefficients
// for [xa,xb] band 
// then calculates gauss chebychev integral
double a[][]=new double[2][n];
a=gauss_chebychev_coefficients(n);
//System.out.println(Matrix.toString(a));

double toplam=0;
double ck;
double x,y;
double z1=0;
for(int k=0;k<n;k++)
{ toplam+=a[1][k]*f_xnt.func(a[0][k]); }
return toplam;
}

      public static void main(String[] args)
      { 
	  f1 b1=new f1();
      System.out.println("integral  : "+gauss_chebychev_integral(b1,50));
      }
}
