// Heat transfer through pin-fin by forced convection
clear all;
clc;
d=40e-3//Diameter of pipe in meter
df=12.5e-3 //Diameter of fin in meter
kf=110 //thermal conductivity of fin material w/m.K 
Lf=150e-3 //Length of fin in meter
xf=20e-3//distance between thermocouplesin meter
pm=1000 //density of manometric fluid in kg/m^3 as manometric fluid is water coloumn for mercury 13534kg/m^3
di=15e-3 //diameter of orifice in meter
w=150e-3 //width of duct in meter
b=100e-3 //Length of duct in meter
fcd=0.62 // coefficient of discharge 
ao=(%pi/4)*(di**2) //cross sectional area of orifice in m^2
af=(%pi/4)*(df**2) //cross sectional area of fin in m^2
P=%pi*df //perimeter of fin 
g=9.81
x1=20e-3
// Input Thermocouple temperature in celsius
t1=35
t2=32
t3=31
t4=30
t5=29
t6=32
//Thermocouple temperature in kelvin
t6k=t6+273
t1k=t1+273
t2k=t2+273
t3k=t3+273
t4k=t4+273
t5k=t5+273
tsk=(t1k+t2k+t3k+t4k+t5k)/5
tfk=(tsk+t6k)/2
pf=(359.99/t6k)+(344.84/(t6k**2))
printf("\n********************************************************************")
printf("\n \t HEAT TRANSFER IN PIN FIN BY FORCED CONVECTION")
printf("\n********************************************************************")
printf("\n perimetr of fin:%f m",P)
printf("\n Area of orifice: %f m^2",ao);
printf("\n Area of fin:%f m^2",af);
printf("\n Thermocouple Temperature T1:%f K",t1k)
printf("\n Thermocouple Temperature T2:%f K",t2k)
printf("\n Thermocouple Temperature T3:%f K",t3k)
printf("\n Thermocouple Temperature T4:%f K",t4k)
printf("\n Thermocouple Temperature T5:%f K",t5k)
printf("\n Thermocouple Temperature T6:%f K",t6k)
// calculation of velocity of air at orifice
ho=20e-2 
num=fcd*sqrt(((2*9.81*ho)*(pm-pf))/pf)
den=1/sqrt(1-(b**4))
vo=num*den
printf("\n The velocity of air at orifice is:%f m/s",vo)
//calculation of velocity of air in duct
va=(vo*ao)/(w*b)
printf("\n The velocity of air in duct is %f m/s",va)
printf("\n********************************************************************")
paf=(359.99/tfk)+(344.84/(tfk**2))
dyvisc=(1.4592*(tfk**(3/2)))/(109.10+tfk)*(1e-6)
renol=(pf*va*d)/dyvisc
nu=0.618*(renol**(0.466))
ka=(2.3340e-3*(tfk**(3/2)))/(164.54+tfk)
h=(nu*ka)/df
m1=(h*P)/(kf*af)
m=sqrt(m1)
cpa=1030.5-(0.19975*t6k)+(3.9734e-4*(t6k**2))
kvisc1=((2.4090e8)/(t6k**(3/2)))+(2.6737e10/(t6k**(5/2)))
kvisc=1/kvisc1
prandtl=(dyvisc*cpa)/ka
printf("\n Mean surface temperature:%f K",tsk)
printf("\n Film temperature:%f K",tfk)
printf("\n Density of air is:%f kg/m^*(-3)",pf)
printf("\n Dynamic viscosity of air is %f Nsm^(-2)",dyvisc)
printf("\n Kinematic viscosity of air is %f m^2/s",kvisc)
printf("\n Thermal conductivity of air is %f W/mK",ka)
printf("\n Specific of air is %f J/Kg.K",cpa)
printf("\n Reynold no:%f",renol)
printf("\n Prandtl no:%f",prandtl)
printf("\n Nusselt no:%f",nu)
printf("\n The heat transfer co-efficient is:%f W/m^2K",h)
printf("\n the value of m is %f",m)
printf("\n *******************************************************************")
n1=tanh(m*Lf)
n2=(m*Lf)
n=n1/n2
E1=tanh(m*Lf)
E2=sqrt((h*af)/(kf*P))
E=E1/E2
printf("\n The Efficiency of the fin is %f",n)
printf("\n The Effectiveness of the fin is %f",E)
printf("\n *******************************************************************")
printf("\n Prediction of Temperature using correlation")
s1=(t1-t6)*cosh(m*Lf)
s2=cosh(m*(Lf-x1))
i=(s1/s2)
to=t6+i
tok=to+273
printf("\n The Base temperature To=%f K",tok)
printf("\n The temperature at distance  x1 is %f K",t1k)
x2=40e-3
x3=60e-3
x4=80e-3
x5=100e-3
s3=(to-t6)*cosh(m*Lf)
    s4=cosh(m*(Lf-x2))
    j=s3/s4
    tx2=t6+j  
    tx2k=tx2+273
     printf("\n The temperature at distance  x2 is %f K",tx2k)
s3=(to-t6)*cosh(m*Lf)
    s5=cosh(m*(Lf-x3))
    j=s3/s5
    tx3=t6+j  
    tx3k=tx3+273
     printf("\n The temperature at distance  x3 is %f K",tx3k)
s3=(to-t6)*cosh(m*Lf)
    s6=cosh(m*(Lf-x4))
    j=s3/s6
    tx4=t6+j  
    tx4k=tx4+273
     printf("\n The temperature at distance  x4 is %f K",tx4k)
s3=(to-t6)*cosh(m*Lf)
    s7=cosh(m*(Lf-x5))
    j=s3/s7
    tx5=t6+j
    tx5k=tx5+273
     printf("\n The temperature at distance  x5 is %f K",tx5k)
deltem=tok-t6k  //change in temperature
q1=sqrt(h*P*kf*af)
q2=(to-t6)*tanh(m*Lf)
Q=q1*q2
printf("\n Change in temperature is %f K",deltem)
printf("\n The heat transfer is %f W",Q)
printf("\n *******************************************************************")

