MATLAB Source Codes
MATLAB Source Codes
T_initial = T; % Initializing
T_old = T;
iteration = 0;
for i = 2:(nx-1)
end
T_old = T;
iteration = iteration + 1;
end
T_initial = T;
end
T_initial = T; % Initializing
T_old = T;
k1 = alpha*(dt/(dx^2));
k2 = alpha*(dt/(dy^2));
iteration = 0;
% Time loop
for i = 2:(nx-1)
node1 = 1/(1+(2*k1)+(2*k2)); % Jacobi method
node2 = k1*node1;
node3 = k2*node1;
a = (T_old((i-1), j) + T_old((i+1), j));
b = (T_old(i, (j-1)) + T_old(i, (j+1)));
T(i,j) =(T_initial(i,j) *
node1)+(a*node2)+(b*node3);
end
end
T_old = T;
iteration = iteration + 1;
end
T_initial = T;
end
figure(1) % Plotting
[c,h] = contourf(x,y,T);
clabel(c,h);
colorbar
colormap(jet)
set(gca,'YDIR','reverse');
xlabel('X Axis');
ylabel('Y Axis');
title({['2D Heat Conduction in Transient State - Implicit method using Jacobi
method.'],['Number of iterations = ',num2str(iteration)]});
Iteration = 0;
for nt = 1: 500
for j = 2:(ny-1)
for i = 2:(nx-1)
node1 = 1/(1+(2*k1)+(2*k2)); % Gauss Seidel method
node2 = k1*node1;
node3 = k2*node1;
a = (T((i-1), j) + T_old((i+1), j));
b = (T(i, (j-1)) + T_old(i, (j+1)));
T(i,j) =(T_initial(i,j) * node1)+(a*node2)+(b*node3);
end
end
T_old = T;
iteration = iteration + 1;
end
T_initial = T;
end
figure(2)
[c,h] = contourf(x,y,T);
clabel(c,h);
colorbar
colormap(jet)
set(gca,'YDIR','reverse');
xlabel('X Axis');
ylabel('Y Axis');
title({['2D Transient Heat Conduction - Implicit method using Gauss Seidel
method.'],['Number of iterations = ',num2str(iteration)]});
error = 1; %reinitialising the error value and the iteration count and
repeat the above steps for SOR method.
iteration = 0;
for nt = 1: 500
for j = 2:(ny-1)
for i = 2:(nx-1)
node1 = 1/(1+(2*k1)+(2*k2));
node2 = k1*node1;
node3 = k2*node1;
a = (T((i-1), j) + T_old((i+1), j));
b = (T(i, (j-1)) + T_old(i, (j+1)));
T(i,j) =(T_initial(i,j) *node1)+(a*node2)+(b*node3);
T(i,j) = T_old(i,j)*(1-alpha)+alpha*T(i,j);
end
end
end
T_initial = T;
end
figure(3)
[c,h] = contourf(x,y,T);
clabel(c,h);
colorbar
colormap(jet)
set(gca,'YDIR','reverse');
xlabel('X Axis');
ylabel('Y Axis');
title({['2D Transient Heat Conduction - Implicit method using SOR method.'],['Number of
iterations = ',num2str(iteration)]});