class fin2 extends Mathd 
{
public static double[][] straightfin(double k, double h, double Tinf, double Tb,double L, double thick, double W,int n)
{
// k    : thermal conductivity W/(mK)
// h    : thermal convectivity W(m2K)
// tinf : environmental temperature
// tb   : base temperature
// L    : the fin height m
// thick    : the fin thickness m
// W    : The fin weight m 
// n : number of data points
double a[][]=new double[2][n];
double P=2*W+2*thick;
double A=W*thick;
double Tetab=Tb-Tinf;
double x;
double m=Math.sqrt(P*h/(k*A));
double T;
for(int i=0;i<n;i++)
{   x=(L*i)/(n-1);
    a[0][i]=x;
	T=Tinf+Tetab*(Math.cosh(m*(L-x)))/(Math.cosh(m*L));
    a[1][i]=T;
	} 
return a;
}

public static double[][] triangularfin(double k, double h, double Tinf, double Tb,double L, double thick, double W,int n)
{
// k    : thermal conductivity W/(mK)
// h    : thermal convectivity W(m2K)
// tinf : environmental temperature
// tb   : base temperature
// L    : the fin height m
// thick    : the fin base thickness m
// W    : The fin weight m 
// n : number of data points
double a[][]=new double[2][n];
double Tetab=Tb-Tinf;
double x;
double m,delta;
for(int i=0;i<n;i++)
{   x=(L*i)/(n-1);
    delta=(L-x)/L*thick;
    m=Math.sqrt(h/k*delta);
    a[0][i]=x;
	a[1][i]=Tinf+Tetab*(bessi0(2.0*m*Mathd.sqrt(L*(L-x)))/bessi0(2.0*m*L));
} 
return a;
}
public static void main(String arg[])
{
double k=50.0;//W/mK
double h=50.0;//W/m2K
double Tinf=20.0;
double Tb=50.0;
double thick=2e-3;
double L=.05;
double W=0.1;
int n=100;
double a[][]=straightfin(k,h,Tinf,Tb,L,thick,W,n);
double b[][]=triangularfin(k,h,Tinf,Tb,L,thick,W,n);
Plot pp=new Plot(a[0],a[1]);
//pp.addData(b[0],b[1]);
pp.plot();	
}


}
