# 2D Heat Transfer Problem Not Yielding Plot

5 views (last 30 days)
Nickolai Serebriakov on 17 Oct 2019
Commented: darova on 17 Oct 2019
Hi everyone, I am attempting to build a 4x4 grid and plot the temperature distribution, however my code is not yielding a graph. There are no errors in the code as far as matlab says. If someone could please point out the problem or help me fix it, I would greatly appreciate it.
%%
function [A,B,T,Temp]=FinDiffFourbyFour
Ttop=1000; %K
Tleft=500; %K
Tright=500; %K
Tbottom=500; %K
w=0.01; %10 cm
l=0.01; %10 cm
xsteps=4;
ysteps=4;
dx=l/(xsteps-1);
dy=w/(ysteps-1);
x=(0:dx:l);
y=(0:dy:w);
A=zeros(xsteps*ysteps,xsteps*ysteps);
B=zeros(xsteps*ysteps,1);
%Top
A(1,1)=1;
B(1)=Ttop;
A(2,2)=1;
B(2)=Ttop;
A(3,3)=1;
B(3)=Ttop;
A(4,4)=1;
B(4)=Ttop;
%Left
A(5,5)=1;
B(5)=Tleft;
A(9,9)=1;
B(9)=Tleft;
%Right
A(8,8)=1;
B(8)=Tright;
A(12,12)=1;
B(12)=Tright;
%Interior
A(6,6)=4;
A(6,2)=-1;
A(6,5)=-1;
A(6,7)=-1;
A(6,10)=-1;
B(6)=0;
A(7,7)=4;
A(7,1)=-1;
A(7,3)=-1;
A(7,6)=-1;
A(7,8)=-1;
B(7)=0;
A(10,10)=4;
A(10,6)=-1;
A(10,9)=-1;
A(10,11)=-1;
A(10,14)=-1;
B(10)=0;
A(11,11)=4;
A(11,7)=-1;
A(11,12)=-1;
A(11,15)=-1;
B(11)=0;
%Bottom
A(13,13)=1;
B(13)=Tbottom;
A(14,13)=1;
B(14)=Tbottom;
A(15,15)=1;
B(15)=Tbottom;
A(16,16)=1;
B(16)=Tbottom;
T=inv(A*B);
%turn back into matrix
for i=1:ysteps
for j=1:xsteps
Temp(i,j)=T(xsteps*ysteps-xsteps*i+j);
end
end
[C,h]=contour(x,y,T); %plot contour
clabel(C,h); %label contour levels
colorbar
xlabel('x-axis')
ylabel('y-axis')
zlabel('Temperature(K)')
title('4x4 Finite Difference Solution')

#### 1 Comment

darova on 17 Oct 2019