Here is my code: I am getting complex values for "T_integral" and that is messing up my temperature profile TSil. Any help will be appreciated.
Lz = 0.00038;
Ft = 1;
Nz = 10;
Nt = 100;
dz = Lz/Nz;
dt = Ft/Nt;
z = linspace(0,Lz,Nz+1);
alpha_Sil = 0.00008;
k_Sil = 149;
d = alpha_Sil*dt/(dz^2);
Ta = 298;
ha = 15;
a_Sil = 52.6;
r_SilAir = 0.34;
t_Sil = 0.9802;
e_Sil = 1 - r_SilAir;
sigma = 5.67037E-08;
F_12 = 0.017517;
Ec = 10.3439;
TSil = 329*ones(1,Nz+1);
TSilnew = TSil;
t = 0;
for kt = 1:Nt+1
t = t + dt;
for kz = 1:Nz+1
Y(kz) = (TSil(1,kz)^4).*exp(-a_Sil*z(kz));
end
T_integral = trapz(z,Y(:));
TSilnew(1) = (((Ec - (r_SilAir*F_12*sigma*(Ta^4)) - (e_Sil*a_Sil*sigma*F_12*T_integral))/(e_Sil*t_Sil*F_12*sigma)).^0.25);
for kz = 2:Nz
TSilnew(kz) = (d/(2*(1+d)))*(TSilnew(kz-1) + TSilnew(kz+1) + TSil(kz-1) + TSil(kz+1)) + ((1-d)/(1+d))*TSil(kz);
end
TSilnew(kz+1) = (d/(1+d-(dz*d*ha/k_Sil)))*(TSilnew(Nz) + TSil(Nz)) + ((1-d-(dz*d*ha/k_Sil))/(1+d-(dz*d*ha/k_Sil)))*TSil(Nz+1) - ((2*dz*ha*d/k_Sil)/(1+d-(dz*d*ha/k_Sil)))*Ta;
TSil = TSilnew;
end