Assignment 2cfd pdf
Assignment 2cfd pdf
ME-864
in
THERMAL ENGINEERING
Submitted By – Submitted To –
Roll No.-242TH013
% Parameters
tic;
L =1.0;
n =9;
dx =0.1;
% Boundary conditions
T_left =300;
T_right =400;
for i = n-1:-1:1
T_interior(i) = (d(i) - c(i) * T_interior(i+1)) / b(i);
end
% Create a table
result_table = table(x_values', temperatures', 'VariableNames', {'x', 'T'});
% Boundary conditions
T_left = 300;
T_right = 400;
% Coefficients
A = -1;
B = 2.0005;
C = -1;
D = 0.1;
% Initialize coefficients and arrays
a = A * ones(1, n);
b = B * ones(1, n);
c = C * ones(1, n);
d = D * ones(1, n);
% Boundary conditions
T_left = 300;
T_right = 400;
% Coefficients
A = -1;
B = 2.0005;
C = -1;
D = 0.1;
% Gauss-Seidel iteration
while error > Error_limit
T_old = T_interior;
for i = 1:n
if i == 1
T_interior(i) = (d(i) - c(i) * T_interior(i + 1)) / b(i);
elseif i == n
T_interior(i) = (d(i) - a(i) * T_interior(i - 1)) / b(i);
else
T_interior(i)=(d(i)-a(i)*T_interior(i-1)-c(i)*T_interior(i+1))/b(i);
end
end
abs_error = max(abs(T_interior - T_old));
error = max(abs((T_interior - T_old) ./ T_interior)) * 100;
error = abs_error;
iteration = iteration + 1;
end
% Boundary conditions
T_left = 300;
T_right = 400;
% Coefficients
A = -1;
B = 2.0005;
C = -1;
D = 0.1;
% Convergence criteria
Error_limit = 1e-5;
error = inf;
iteration = 0;
% Relaxation factor
w_opt= 1.53;
% iteration table
fprintf('Iteration\tMax Error (Absolute)\tMax Error (Percentage)\n');
% SOR iteration
while error > Error_limit
T_old = T_interior;
for i = 1:n
if i == 1
T_new=(d(i)-c(i)*T_interior(i + 1))/b(i);
elseif i == n
T_new=(d(i)-a(i) * T_interior(i-1))/b(i);
else
T_new=(d(i)-a(i)*T_interior(i-1)-c(i)*T_interior(i+1))/b(i);
end
T_interior(i)=T_interior(i)+w_opt*(T_new - T_interior(i));
end
abs_error = max(abs(T_interior - T_old));
percent_error = max(abs((T_interior - T_old) ./ T_interior)) * 100;
error = abs_error;
iteration = iteration + 1;
end
1400
1200
1000
Number of Iterations
800
600
400
200
0
0 0.5 1 1.5 2 2.5
Relaxation Factor
Table-4:
Iterative Number of Elapsed
Methods Iterations time(seconds)
SOR 28 0.005307
Inferences:
The study involved solving the fin equation using four numerical methods:
TDMA, Jacobi, Gauss-Seidel, and Successive Over-Relaxation (SOR). Clearly,
SOR is a very efficient method if the optimum value of the relaxation factor is
known.The results indicate that all methods produced accurate temperature
profiles, as confirmed by their alignment with the analytical solution. Among the
iterative methods, SOR demonstrated the highest efficiency, converging in just
28 iterations with an optimal relaxation factor (w_opt) of 1.53, compared to 107
iterations for Gauss-Seidel and 304 for Jacobi. The computational time also
reflected this efficiency, with SOR requiring the least time (0.0053 seconds)
compared to Jacobi (0.0071 seconds) and Gauss-Seidel (0.0058 seconds).
Additionally, the relaxation factor directly influenced the convergence speed,
with higher values of w generally leading to faster convergence up to an optimal
point. These findings highlight the practical advantages of using optimized
iterative methods like SOR for solving heat transfer problems efficiently.