import java.io.*;

class HT_plane_FD
{    
  public static double [] thomas(double a[][],double r[])
  {
  //
  int n=a.length;
  double f[]=new double[n];
  double e[]=new double[n];
  double g[]=new double[n];
  double x[]=new double[n];
  for(int i=0;i<n;i++)     {f[i]=a[i][i];}
  for(int i=0;i<(n-1);i++) {g[i]=a[i][i+1];}
  for(int i=0;i<(n-1);i++) {e[i+1]=a[i+1][i];}
  for(int k=1;k<n;k++)
     {e[k]=e[k]/f[k-1];
      f[k]=f[k]-e[k]*g[k-1];
     }
  for(int k=1;k<n;k++)
     {r[k]=r[k]-e[k]*r[k-1];
     }
  x[n-1]=r[n-1]/f[n-1];   
  for(int k=(n-2);k>=0;k--)
     {x[k]=(r[k]-g[k]*x[k+1])/f[k];}
  return x;      
  }
  
  public static double [] thomas(double f[],double e[],double g[],double r[])
  {
  int n=f.length;
  double x[]=new double[n];
  for(int k=1;k<n;k++)
     {e[k]=e[k]/f[k-1];
      f[k]=f[k]-e[k]*g[k-1];
     }
  for(int k=1;k<n;k++)
     {r[k]=r[k]-e[k]*r[k-1];
     }
  x[n-1]=r[n-1]/f[n-1];   
  for(int k=(n-2);k>=0;k--)
     {x[k]=(r[k]-g[k]*x[k+1])/f[k];}
  return x;      
  }
  
  public static double [] HT_planecoz( double L,double W,double dx)
  {
  //Assume dx=dy=const;
  int nx=L/dx;
  int ny=W/dx;
  double A[][]=new double[nx][ny];
  // boundary conditions
  for(int i=0;i<nx;i++)
  {   
     for(int j=0;j<ny;j++)
     {
     if(i==0) {A[i][j]=0.0;}
     if(i==(nx-1)) {A[i][j]=0.0;}
     if(j==0) {A[i][j]=0.0;}
     if(j==(ny-1)) {A[i][j]=1.0;}
     }
  }
  for(int i=1;i<(nx-1);i++)
  {   
     for(int j=1;j<(ny-1);j++)
     {
     if(i==j) {A[i][j]+=4.0;}
     if((i==(j+1) ||(i==(j-1) ) {A[i][j]+=1.0;}
     }
  }
  
  double T[]=new double[n+1];
  double a[]=thomas(f,e,g,r);
  T[0]=tetab;
  for(int i=0;i<n;i++) {T[i+1]=a[i];}
  return T;
  }
       
  public static void main(String args[]) throws IOException
  {
  int n=10;
  double L=1.0;
  double m=1.0;
  double dT=10.0;
  double dx=L/n;
  double T[]=kanatcoz(L,m,dT,n);  
  double z1i[]=new double[n+1];
  double z2i[]=new double[n+1];
  double x=0;
  for(int i=0;i<n+1;i++)
  {   z1i[i]=x;
	  z2i[i]=dT*Math.cosh(L-x)/Math.cosh(L);
      x+=dx;
  }
  Plot pp=new Plot(z1i,T);
  pp.addData(z1i,z2i);  
  pp.plot();
  Text.printT(T,"sonlu eleman sıcaklık profili");  
  }
}