# Heat Transfer: Matlab 2D Conduction

• Singed5059
In summary: Ny-1)%m = 1i = (n-1)*Nx + 1;A(i,i) = -3; % main diagonal elementA(i,i+1) = 1; % right-side elementA(i,i+Nx) = 1; % top elementA(i,i-Nx) = 1; % bottom elementC(i) = -Tleft; % right-hand side of equationend%right:for n=2:(Ny-1)%m = Nxi = (n-1)*Nx + Nx;A(i,i) = -3; % main diagonal elementA(i,i-1) = 1; % left-side elementA(i,i
Singed5059

## Homework Statement

Having trouble with code as seen by the gaps left where it asks me to add things like the coefficient matrices. Any Numerical Conduction MATLAB wizzes out there?
A long square bar with cross-sectional dimensions of 30 mm x 30 mm has a specied temperature on each side, The temperatures are:

Tbottom = 100 C
Ttop = 150 C
Tleft = 250 C
Tright = 300 C

Assuming isothermal surfaces, write a software program to solve the heat equation to determine the two-dimensional
steady-state spatial temperature distribution within the bar.
Your analysis should use a finite difference discretization of the heat equation in the bar to establish a system of equations:

## Homework Equations

AT = C

Must use Gauss-Seidel Method to solve the system of equations

## The Attempt at a Solution

clear all
close all

%Specify grid size
Nx = 10;
Ny = 10;

%Specify boundary conditions
Tbottom = 100
Ttop = 150
Tleft = 250
Tright = 300

% initialize coefficient matrix and constant vector with zeros
A = zeros(Nx*Ny);
C = zeros(Nx*Ny,1);

% initial 'guess' for temperature distribution
T(1:Nx*Ny,1) = 100;

% Build coefficient matrix and constant vector

% inner nodes
for n = 2:(Ny-1)
for m = 2:(Nx-1)
i = (n-1)*Nx + m;
DEFINE COEFFICIENT MATRIX ELEMENTS HERE
end
end

% Edge nodes

% bottom
for m = 2:(Nx-1)
6%n = 1
i = m;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

end
%top:
for m = 2:(Nx-1)
% n = Ny
i = (Ny-1)*Nx + m;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

end
%left:
for n=2:(Ny-1)
%m = 1
i = (n-1)*Nx + 1;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

end
%right:
for n=2:(Ny-1)
%m = Nx
i = (n-1)*Nx + Nx;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

end
% Corners
%bottom left (i=1):
i=1

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

%bottom right:
i = Nx

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

C(Nx) = -(Tbottom + Tright);
%top left:
i = (Ny-1)*Nx + 1;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

%top right:
i = Nx*Ny;

DEFINE COEFFICIENT MATRIX AND CONSTANT VECTOR ELEMENTS HERE

%Solve using Gauss-Seidel
residual = 100;
iterations = 0;
while (residual > 0.0001) % The residual criterion is 0.0001 in this example
7% You can test different values
iterations = iterations+1
%Transfer the previously computed temperatures to an array Told
Told = T;
%Update estimate of the temperature distribution

INSERT GAUSS-SEIDEL ITERATION HERE

%compute residual
deltaT = abs(T - Told);
residual = max(deltaT);
end
iterations % report the number of iterations that were executed
%Now transform T into 2-D network so it can be plotted.
delta_x = 0.03/(Nx+1)
delta_y = 0.03/(Ny+1)
for n=1:Ny
for m=1:Nx
i = (n-1)*Nx + m;
T2d(m,n) = T(i);
x(m) = m*delta_x;
y(n) = n*delta_y;
end
end
T2d
surf(x,y,T2d)
figure
contour(x,y,T2d

## The Attempt at a Solution

clear allclose all%Specify grid sizeNx = 10;Ny = 10;%Specify boundary conditionsTbottom = 100Ttop = 150Tleft = 250Tright = 300% initialize coefficient matrix and constant vector with zerosA = zeros(Nx*Ny);C = zeros(Nx*Ny,1);% initial 'guess' for temperature distributionT(1:Nx*Ny,1) = 100;% Build coefficient matrix and constant vector% inner nodesfor n = 2:(Ny-1)for m = 2:(Nx-1)i = (n-1)*Nx + m;A(i,i) = -4; % main diagonal elementA(i,i+1) = 1; % right-side elementA(i,i-1) = 1; % left-side elementA(i,i+Nx) = 1; % top elementA(i,i-Nx) = 1; % bottom elementC(i) = 0; % right-hand side of equationendend% Edge nodes% bottomfor m = 2:(Nx-1)%n = 1i = m;A(i,i) = -3; % main diagonal elementA(i,i+1) = 1; % right-side elementA(i,i-1) = 1; % left-side elementA(i,i+Nx) = 1; % top elementC(i) = -Tbottom; % right-hand side of equationend%top:for m = 2:(Nx-1)% n = Nyi = (Ny-1)*Nx + m;A(i,i) = -3; % main diagonal elementA(i,i+1) = 1; % right-side elementA(i,i-1) = 1; % left-side elementA(i,i-Nx) = 1; % bottom elementC(i) = -Ttop; % right-hand side of equationend

## 1. What is heat transfer and why is it important?

Heat transfer is the movement of thermal energy from one object or system to another. It is important because it plays a crucial role in many natural and industrial processes, such as maintaining a comfortable temperature in our homes, cooking food, and powering engines.

## 2. What is Matlab 2D conduction and how does it work?

Matlab 2D conduction is a computational tool used to model heat transfer in two-dimensional systems. It works by solving the heat diffusion equation, which describes how heat is transferred within a material due to temperature differences.

## 3. How is heat transfer modeled in Matlab 2D conduction?

Heat transfer in Matlab 2D conduction is modeled using the finite difference method, which divides the system into a grid of small elements and calculates the temperature at each point based on the temperature gradient and thermal properties of the material.

## 4. What are some applications of Matlab 2D conduction?

Matlab 2D conduction is commonly used in engineering and scientific research to study heat transfer in various systems, such as heat exchangers, electronic devices, and buildings. It can also be used to design and optimize thermal systems for improved efficiency.

## 5. Are there any limitations to using Matlab 2D conduction?

Like any computational tool, Matlab 2D conduction has its limitations. It assumes steady-state conditions and homogeneous material properties, which may not always be the case in real-world scenarios. It also requires accurate input data and may not be suitable for complex geometries.

Replies
1
Views
2K
Replies
2
Views
3K
Replies
0
Views
4K
Replies
9
Views
2K
Replies
12
Views
3K
Replies
1
Views
2K
Replies
10
Views
2K
Replies
1
Views
2K
Replies
3
Views
1K
Replies
1
Views
2K