Problem: Consider steady two-dimensional heat transfer in a long solid body whose cross section is given in the figure. The measured temperatures at selected points of the outer surface areas shown. The thermal conductivity of the body is k = 45 W/m · °C, and there is no heat generation. Using the finite difference method with a mesh size of ∆x = ∆y = 2.0 cm, determine the temperatures at the indicated points in the medium.

Solution:
Assumptions:
1.      Heat Transfer through the body is given to be steady and two-dimensional.
2.      There is no heat generation in the body.
Properties:
Thermal conductivity of the body is given to be k = 45 W/m · °C
Analysis:
The mesh size is given to be x = y = 2.0 cm means square grid. The general finite difference form of an interior node of square grid for steady two-dimensional heat conduction for the case of no heat generation is expressed as:
Tm+1, n + Tm-1, n + Tm, n+1 + Tm, n-1 – 4 Tm, n = 0
The equation for node 1:
180 + T2 + 180 + T4 – 4 T1 = 0
ð  4 T1 – T2 – T4 = 360
The equation for node 2:
T1 + T3 + 200 + T5 – 4 T2 = 0
ð   T1 – 4 T2 + T3 + T5 =  200
The equation for node 3:
T2 + 180 + 180 + T6 – 4 T3 = 0
ð   T2 – 4 T3 + T6 = 360
The equation for node 4:
200 + T5 + T1 + T7 – 4 T4 = 0
ð   T1 – 4 T4 + T5 + T7 =  200
The equation for node 5:
T4 + T6 + T2 + T8 – 4 T5 = 0
ð  T2 + T4 – 4 T5 + T6 + T8 = 0
The equation for node 6:
T5 + 200 + T3 + T9 – 4 T6 = 0
ð   T3 + T5 – 4 T6 + T9 =  200
The equation for node 7:
180 + T8 + T4 + 180 – 4 T7 = 0
ð   T4 – 4 T7 + T8 =  360
The equation for node 8:
T7 + T9 + T5 + 200 – 4 T8 = 0
ð   T5 + T7 – 4 T8 + T9 =  200
The equation for node 9:
T8 + 180 + T6 + 180 – 4 T9 = 0
ð   T6 + T8 – 4 T9 =  360

Thus, we get nine equations and nine unknown nodal temperatures.
The above equations can be written in the matrix form like below:

Now, solve this matrix by Matrix Inversion Method using MATLAB:
Code:
clc
clear all
close all

A = [4 -1 0 -1 0 0 0 0 0;
1 -4 1 0 1 0 0 0 0;
0 1 -4 0 0 1 0 0 0;
1 0 0 -4 1 0 1 0 0;
0 1 0 1 -4 1 0 1 0;
0 0 1 0 1 -4 0 0 1;
0 0 0 1 0 0 -4 1 0;
0 0 0 0 1 0 1 -4 1;
0 0 0 0 0 1 0 1 -4]
D = [360;
-200;
-360;
-200;
0;
-200;
-360;
-200;
-360]
T = inv(A) * D;
T1 = T(1)
T2 = T(2)
T3 = T(3)
T4 = T(4)
T5 = T(5)
T6 = T(6)
T7 = T(7)
T8 = T(8)
T9 = T(9)
Output:
A =
4    -1     0    -1     0     0     0     0     0
1    -4     1     0     1     0     0     0     0
0     1    -4     0     0     1     0     0     0
1     0     0    -4     1     0     1     0     0
0     1     0     1    -4     1     0     1     0
0     0     1     0     1    -4     0     0     1
0     0     0     1     0     0    -4     1     0
0     0     0     0     1     0     1    -4     1
0     0     0     0     0     1     0     1    -4
D =
360
-200
-360
-200
0
-200
-360
-200
-360
T1 = 185
T2 = 190
T3 = 185
T4 = 190
T5 = 190
T6 = 190
T7 = 185
T8 = 190
T9 = 185

So, the temperatures we obtain at the indicated nodes:

T1 = T3 = T7 = T9 = 185 C
T2 = T4 = T5 = T6 = T8 = 190 C