All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective: To solve steady and unsteady 2D heat conduction equation using different iterative techniques for implicit and explicit methods in MATLAB. Introduction: Assumptions: - The domain is a square domain - Number of points along the 'x-direction' is equal to the number of points along the 'y-direction'…
Nikith M
updated on 28 Jan 2020
Objective: To solve steady and unsteady 2D heat conduction equation using different iterative techniques for implicit and explicit methods in MATLAB.
Introduction:
Assumptions:
- The domain is a square domain
- Number of points along the 'x-direction' is equal to the number of points along the 'y-direction' (nx=ny)
- Boundary conditions : * Left side: 400K
* Right side: 800K
* Top side: 600K
* Bottom side: 900K
- Absolute error is taken as 1e-4
2D Heat Conduction Equation:
Steady State: ∂2T∂x2+∂2T∂y2=0
UnSteady State: ∂2T∂x2+∂2T∂y2=(1α)∂T∂t
Steady State:
Steady State
clear all
close all
clc
% Given Conditions
nx = 10;
ny = 10;
% Domain is unit square along x and y
x = linspace(0,1,nx);
y = linspace(0,1,ny);
dx = 1/(nx-1);
dy = 1/(ny-1);
% let the initial temp be 100k
T = 100*ones(nx,ny);
% BC
T(:,1) = 400; % Left
T(:,nx) = 800; % Right
T(1,:) = 600; % Top
T(ny,:) = 900; % Bottom
% Tolerance and eeror
error = 9e9;
absolute_error = 1e-4;
% STEADY STATE ANALYSIS
% EXPLICIT METHOD
T_old = T;
T_initial = T;
solver = input('number =');
alpha = 1.25;
K = 2*(dx^2+dy^2)/((dx^2)*(dy^2));
% JACOBI
tic;
if solver == 1
jacobi_iter=1;
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = (K^-1)*((T_old(i-1,j)+T_old(i+1,j))/(dx^2)+(T_old(i,j+1)+T_old(i,j-1))/(dy^2));
end
end
error = max(max(abs(T-T_old)));
T_old = T;
jacobi_iter = jacobi_iter+1;
toc
simulation_steady_jacobi = toc;
end
figure(1)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Steady state Jacobi Iteration =%d, simulation time =%s', jacobi_iter, simulation_steady_jacobi);
title(title_text)
pause(0.0005)
end
% Gauss Siedel Method
tic;
if solver ==2
gauss_iter = 1;
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = (K^-1)*((T(i-1,j)+T_old(i+1,j))/(dx^2)+(T_old(i,j+1)+T(i,j-1))/(dy^2));
end
end
error = max(max(abs(T-T_old)));
T_old = T;
gauss_iter = gauss_iter+1;
toc
simulation_steady_gauss = toc;
end
figure(2)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Steady State Gauss Iteration =%d, Simulation time =%s', gauss_iter, simulation_steady_gauss);
title(title_text)
pause(0.0005)
end
% Successive over relaxation
tic;
if solver == 3;
sor_iter=1;
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
k1 = (T(i-1,j)+T_old(i+1,j))/(dx^2);
k2 = (T_old(i,j+1)+T(i,j-1))/(dy^2);
T_gauss(i,j) = (k1+k2)/K;
T(i,j) = T_old(i,j)*(1-alpha)+alpha*(T_gauss(i,j));
end
end
error = max(max(abs(T-T_old)));
T_old = T;
sor_iter = sor_iter+1;
toc
simulation_steady_sor=toc;
end
figure(3)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Steady State SOR Iteration =%d, Simulation time =%s', sor_iter, simulation_steady_sor);
title(title_text)
pause(0.0005)
end
Plots for the Steady State Analysis
Figure 1: Jacobi
Figure 2: Gauss Siedel
Figure 3: SOR
Transient Explicit
% TRANSIENT EXPLICIT METHOD
close all
clear all
clc
% Given conditions
nx = 10;
ny = 10;
% Domain is unit square along x and y
x = linspace(0,1,nx);
y = linspace(0,1,ny);
dx = 1/(nx-1);
dy = 1/(ny-1);
% Time step dt
dt = 1e-2;
nt = 2/dt;
% Initial temperature be 100k
T = 100*ones(nx,ny);
% BC
% BC
T(:,1) = 400; % Left
T(:,nx) = 800; % Right
T(1,:) = 600; % Top
T(ny,:) = 900; % Bottom
% Tolerance and error
error = 9e9;
absolute_error = 1e-4;
beta = 0.25;
alpha = 1.25;
% Transient state analysis
m1 = beta*dt/(dx^2);
m2 = beta*dt/(dy^2);
m = 1-(2*m1)-(2*m2);
% Storing the initial values of T
T_old = T;
T_initial = T;
solver = input('number = ');
% EXPLICIT METHOD
% JACOBI
tic
jacobi_iter = 1;
if solver == 1
for s = 1:nt
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = T_old(i,j)*m+m1*(T_old(i+1,j)+T_old(i-1,j))+m2*(T_old(i,j+1)+T_old(i,j-1));
end
end
error = max(max(abs(T-T_old)));
jacobi_iter = jacobi_iter+1
T_old = T;
end
end
toc
transient_explicit_jacobi = toc;
% Plot
figure(4)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit Jacobi Iteration =%d, simulation time =%s', jacobi_iter, transient_explicit_jacobi);
title(title_text)
pause(0.0005)
end
% Gauss Siedel
tic
if solver == 2
gauss_iter = 1;
for s = 1:nt
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = T_old(i,j)*m+m1*(T_old(i+1,j)+T(i-1,j))+m2*(T_old(i,j+1)+T(i,j-1));
end
end
error = max(max(abs(T-T_old)));
gauss_iter = gauss_iter+1
T_old = T;
end
end
toc
transient_explicit_gauss = toc;
% Plot
figure(5)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit Gauss Iteration =%d, simulation time =%s', gauss_iter, transient_explicit_gauss);
title(title_text)
pause(0.0005)
end
% SOR
tic
if solver == 3
sor_iter = 1;
for s = 1:nt
while (error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = T_old(i,j)*(1-alpha)+alpha*(T_old(i,j)*m+m1*(T_old(i+1,j)+T(i-1,j))+m2*(T_old(i,j+1)+T(i,j-1)));
end
end
error = max(max(abs(T-T_old)));
sor_iter = sor_iter+1
T_old = T;
end
end
toc
transient_explicit_sor = toc;
% Plot
figure(6)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit SOR Iteration =%d, simulation time =%s', sor_iter, transient_explicit_sor);
title(title_text)
pause(0.0005)
end
Plots for Transient Explicit Method
Figure 4: Jacobi
Figure 5: Gauss Siedel
Figure 3: SOR
Transient Implicit
% TRANSIENT IMPLICIT METHOD
close all
clear all
clc
% Given conditions
nx = 10;
ny = 10;
% Domain is unit square along x and y
x = linspace(0,1,nx);
y = linspace(0,1,ny);
dx = 1/(nx-1);
dy = 1/(ny-1);
% Time step dt
dt = 1e-2;
nt = 2/dt;
% Initial temperature be 100k
T = 100*ones(nx,ny);
% BC
T(:,1) = 400; % Left
T(:,nx) = 800; % Right
T(1,:) = 600; % Top
T(ny,:) = 900; % Bottom
% Tolerance and error
error = 9e9;
absolute_error = 1e-4;
beta = 0.25;
alpha = 1.25;
% Storing the initial values of T
T_old = T;
T_initial = T;
solver = input('number = ');
% IMPLICIT METHOD
k1 = (beta*dt/(dx^2));
k2 = (beta*dt/(dy^2));
k = 1+(2*k1)+(2*k2);
% JACOBI
tic
jacobi_iter = 1;
if solver == 1
for s = 1:nt
while(error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T_left = T_old(i-1,j);
T_right = T_old(i+1,j);
T_top = T_old(i,j+1);
T_bottom = T_old(i,j-1);
T(i,j) = ((T_initial(i,j)+k1*(T_left+T_right)+k2*(T_top+T_bottom))/k);
end
end
error = max(max(abs(T-T_old)));
T_old = T;
jacobi_iter = jacobi_iter+1
end
end
toc
transient_implicit_jacobi = toc;
% Plot
figure(1)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit Jacobi Iteration =%d, simulation time =%s', jacobi_iter, transient_implicit_jacobi);
title(title_text)
pause(0.0005)
end
% GAUSS SIEDEL
tic
gauss_iter = 1;
if solver == 2
for s = 1:nt
while(error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T_left = T(i-1,j);
T_right = T(i+1,j);
T_top = T(i,j+1);
T_bottom = T(i,j-1);
T(i,j) = ((T_initial(i,j)+k1*(T_left+T_right)+k2*(T_top+T_bottom))/k);
end
end
error = max(max(abs(T-T_old)));
T_old = T;
gauss_iter = gauss_iter+1
end
end
toc
transient_implicit_gauss = toc;
% Plot
figure(1)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit Gauss Iteration =%d, simulation time =%s', gauss_iter, transient_implicit_gauss);
title(title_text)
pause(0.0005)
end
% SOR
tic
sor_iter = 1;
if solver == 3
for s = 1:nt
while(error>absolute_error)
for i = 2:nx-1
for j = 2:ny-1
T_left = T(i-1,j);
T_right = T(i+1,j);
T_top = T(i,j+1);
T_bottom = T(i,j-1);
T(i,j) = (1-alpha)*(T_old(i,j))+alpha*((T_initial(i,j)+k1*(T_left+T_right)+k2*(T_top+T_bottom))/k);
end
end
error = max(max(abs(T-T_old)));
T_old = T;
sor_iter = sor_iter+1
end
end
toc
transient_implicit_sor = toc;
% Plot
figure(1)
[X,Y] = contourf(x,y,T);
clabel(X,Y)
colormap(jet)
colorbar
xlabel('X-Axis')
ylabel('Y-Axis')
title_text =sprintf('Transient Explicit SOR Iteration =%d, simulation time =%s', sor_iter, transient_implicit_sor);
title(title_text)
pause(0.0005)
end
Plots for Transient Implicit Method
Figure 7: Jacobi
Figure 8: Gauss Siedel
Figure 9: SOR
Conclusion
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Steady Vs Unsteady (Mid Term)
Objective: To solve steady and unsteady 2D heat conduction equation using different iterative techniques for implicit and explicit methods in MATLAB. Introduction: Assumptions: - The domain is a square domain - Number of points along the 'x-direction' is equal to the number of points along the 'y-direction'…
28 Jan 2020 03:33 AM IST
1D Linear Convection (Grid points)
Objective: Write a MATLAB Code and to solve 1D linear equation Given Data: Length( L ) = 1m Convective Coeffieient( C ) = 1 Time step( dt ) = 0.01 Grid point( n ) = [20,40,80,160]…
08 Dec 2019 01:56 AM IST
Linear Convection Effect of Time steps on Solution
Objective: To write a MATLAB program that solves a 1D Linear equation for various time-steps. Given Data: Length( L ) = 1m Convective Coeffieient( C ) = 1 Time step( dt ) = (1e-1,1e-2,1e-3,1e-4)…
05 Dec 2019 11:56 PM IST
Discretization basics Numerical derivative vs. exact derivative
Objective: Write a program that compares the first, second and fourth-order approximations of the first derivative against the analytical/exact derivative. Given Function : f(x)=sin(x)x3 First derivative of the function is f'(x)=x3cos(x)−sin(x)⋅3x2x6 The function is computed at x=π3 First-order…
05 Dec 2019 11:56 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.