import java.io.*;

class kanat2
{    
  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 [] kanatcoz( double L,double m,double tetab,int n)
  {
  double f[]=new double[n];
  double e[]=new double[n];  
  double g[]=new double[n]; 
  double r[]=new double[n];
  double dx=L/n;
  double xf=-2-m*m*dx*dx;
  double xe=1.0;
  double xg=1.0;
  for(int i=0;i<n;i++)
  {  f[i]=xf; 
     if(i==0) {e[i]=0;r[i]=-tetab;g[i]=1.0;}
     else if(i==(n-1)) {e[i]=2.0;r[i]=0.0;g[i]=0.0;}
     else {e[i]=1.0;r[i]=0.0;g[i]=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]=10*Math.cosh(1-x)/Math.cosh(1);
      x+=dx;
  }
  Plot pp=new Plot(z1i,T);
  pp.addData(z1i,z2i);  
  pp.plot();
  Text.printT(T,"sonlu eleman sıcaklık profili");  
  }
}