I am running a matrix off of a nested for loop. My problem here is that the values come out wrong because the loop fills the matrix row by row. I would like to have the loop fill the matrix column by column to avoid this issue.
T_i = 85; %Initial temperature (K)
T_inf = 20; %Free stream temperature (K)
h = 50; %Convection heat transfer coefficient (W/m^2K)
alp = 0.0000015; %Thermal diffusivity (m^2/s)
k = 15; %Thermal conductivity (W/mK)
del_x = 0.03; %Incremental distance between center nodes (m)
del_t = 300; %Incremental time diference (s)
Fo = alp*del_t/(del_x^2) %Find the Numerical/Discretized Fourier Number
Bi = h*del_x/k %Find the Numerical/Discretized Biot Number
T__vec = [85;85;85;85] %Initial temperature vector for 4 node points.
%T_inf_vec = 20+zeros(1:10)
M=5 %No. of rows
N=10 %No. of columns
T_inf_vec = [20,20,20,20,20,20,20,20,20,20]
A=zeros(M,N);
A(1:4)= T__vec;
A = [T_inf_vec;A];
for i=2:M
for j=2:N
T_p1=(2*Fo*A(i+1,j-1))+(2*Bi*Fo*A(i-1,j-1))+(((1-2*Fo)-(2*Bi*Fo))*A(i,j-1))
T_p11 = Fo*A(i-1,j-1)-2*Fo*A(i,j-1)+A(i,j-1)+Fo*A(i+1,j-1);
if i==2
A(i,j)= T_p1
elseif i<1
A(i,j)= 20
else
A(i,j)= T_p11
end
end
end
Any help ASAP would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire