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*x);
  }
}

public class NA64 
{
	
public static double[][] gauss_hermite_coefficients(int n)
{
    double a[][]=new double[2][n];
    int i;
    int j;
    double r=0;
    double r1;
    double p1;
    double p2;
    double p3;
    double dp3;
    double pipm4;
    double eps=1e-10;
    pipm4 = Math.pow(Math.PI, -0.25);
    for(i = 0; i <= (n+1)/2-1; i++)
    {
        if( i==0 )
        { r =Math.sqrt((double)(2*n+1))-1.85575*Math.pow((double)(2*n+1), -1.0/6.0);}
        else if( i==1 )
            { r = r-1.14*Math.pow((double)(n), 0.426)/r; }
        else if( i==2 )
                { r = 1.86*r-0.86*a[0][0];}
        else if( i==3 )
                { r = 1.91*r-0.91*a[0][1];}
        else
                {r = 2*r-a[0][i-2];}
    do {
            p2 = 0;
            p3 = pipm4;
            for(j = 0; j <= n-1; j++)
            {   p1 = p2;
                p2 = p3;
                p3 = p2*r*Math.sqrt(2.0/(double)(j+1))-p1*Math.sqrt((double)(j)/(double)(j+1));
            }
            dp3 = Math.sqrt((double)(2.0*j))*p2;
            r1 = r;
            r = r-p3/dp3;
        }
        while(Math.abs(r-r1)>=eps*(1+Math.abs(r))*100.0);
    a[0][i] = r;
    a[1][i] = 2.0/(dp3*dp3);
    a[0][n-1-i] = -a[0][i];
    a[1][n-1-i] = a[1][i];
   }
   return a;
}

public static double gauss_hermite_integral(f_x f_xnt,int n)
{
//n : number of integral coefficients
// this routine first generates gauss hermite coefficients
// for [x1,x2] band 
// then calculates gauss hermite integral
double a[][]=new double[2][n];
a=gauss_hermite_coefficients(n);
System.out.println(Matrix.toString(a));
double z=0;
for(int i=0;i<n;i++)
{ z+=a[1][i]*f_xnt.func(a[0][i])*Math.exp(a[0][i]*a[0][i]);}
return z;
}

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