MATLAB Code help Heat transfer

  • Thread starter MEAHH
  • Start date
  • #1
10
0
Hi so i have a heat transfer project to determine the material (aka the thermal conductivity) and length of a 2d wall. It has to have between -1 and 1 net rate of heat loss from the southern side and above 145 rate of heat transfer from the eastern side. The wall is 20 cm high na the boundry conditions are given in the code....
#1 I cannot find a material/length combo that satisfys the Q rateconditions so i wonder if my code is wrong?I was really unsure of how to do the equations for the heat rate of the specified sides, how do you find the heat rate of a given side with nodal temps known, heat conduction and convection?
#2 I have to plot the temp in the wall as a function of x position for y=0,10 an 20cm...how would i do this....
Heres the code i wrote so far

%Heat Transfer Project
%Material chosen was:
%Length Chosen was:
%Inputs, Given Values in degrees C, m, and
Tn=100;
hn=20;
Te=20;
he=15;
Ts=70;
hs=30;
Tw=40;
hw=20;
H=0.2;
L=.5;
k=0.14;
I=21;
J=21;

%Geometry
deltax=L/(I-1);
deltay=L/(J-1);
x=[0:0.1:L];
y=[0:0.1:H];
A=L*H;
%Iterative loop
T=ones(I,J)*Tw;
Dum=1;
while Dum==1
Told=T;
%Numeric Equations
%Interior Control Volumes
for i=2,I-1;
for j=2,J-1;
T(i,j)=(k*deltay*T(i-1,j)+k*deltay*T(i+1,j)+k*deltax*T(i,j-1)-k*deltax*T(i,j+1))/(2*k*deltay+2*k*deltax);
end
end

%West & East sides
for j=2,J;
T(1,j)=(-hw*deltay*Tw-(k*deltax)/(2*deltay)*T(1,j+1)-(k*deltax)/(2*deltay)*T(1,j-1)-(k*deltay)/deltax*T(2,j))/(-hw*deltay-2*((k*deltax)/(2*deltay))-(k*deltax)/(deltay));
T(I,j)=(-he*deltay*Te-(k*deltax)/(2*deltay)*T(I,j+1)-(k*deltax)/(2*deltay)*T(I,j-1)-(k*deltay)/deltax*T(I-1,j))/(-he*deltay-2*((k*deltax)/(2*deltay))-(k*deltax)/(deltay));
end

%South & North
for i=2,I;
T(i,1)=(-hs*deltax*Ts-(k*deltay)/(2*deltax)*T(i+1,1)-(k*deltay)/(2*deltax)*T(i-1,1)-(k*deltax)/deltay*T(i,2))/(-hs*deltax-2*((k*deltay)/(2*deltax))-(k*deltay)/(deltax));
T(i,J)=(-hn*deltax*Tn-(k*deltay)/(2*deltax)*T(i+1,J)-(k*deltay)/(2*deltax)*T(i-1,J)-(k*deltax)/deltay*T(i,J-1))/(-hn*deltax-2*((k*deltay)/(2*deltax))-(k*deltay)/(deltax));
end

%Four Coners
T(1,1)=((-hw*Tw*deltay)/2-(hs*Ts*deltax)/2-(k*deltay)/(2*deltax)*T(2,1)-(k*deltax)/(2*deltay)*T(1,2))/(-(hw*deltay)/2-(hs*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(I,1)=((-he*Te*deltay)/2-(hs*Ts*deltax)/2-(k*deltay)/(2*deltax)*T(I-1,1)-(k*deltax)/(2*deltay)*T(I,2))/(-(he*deltay)/2-(hs*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(1,J)=((-hw*Tw*deltay)/2-(hn*Tn*deltax)/2-(k*deltay)/(2*deltax)*T(2,J)-(k*deltax)/(2*deltay)*T(1,J))/(-(hw*deltay)/2-(hn*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(I,J)=((-he*Te*deltay)/2-(hn*Tn*deltax)/2-(k*deltay)/(2*deltax)*T(I-1,J)-(k*deltax)/(2*deltay)*T(I,J-1))/(-(he*deltay)/2-(hn*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
%Check for convergence
Dum=0;
for i=1,I;
for j=1,J;
if (abs((Told(i,j)-T(i,j))/T(i,j))>0.0000001)
Dum=1;
end
end
end
end

Qe=he*deltay*[(T(I,1)-Te)/2+(T(I,2)-Te)+(T(I,3)-Te)+(T(I,4)-Te)+(T(I,5)-Te)+(T(I,6)-Te)+(T(I,7)-Te)+(T(I,8)-Te)+(T(I,9)-Te)+(T(I,10)-Te)+(T(I,11)-Te)+(T(I,12)-Te)+(T(I,13)-Te)+(T(I,14)-Te)+(T(I,15)-Te)+(T(I,16)-Te)+(T(I,17)-Te)+(T(I,19)-Te)+(T(I,20)-Te)+(.5*T(I,J)-Te)]
Qs=hs*deltax*[(T(1,1)-Ts)/2+(T(2,1)-Ts)+(T(3,1)-Ts)+(T(4,1)-Ts)+(T(5,1)-Ts)+(T(6,1)-Ts)+(T(7,1)-Ts)+(T(8,1)-Ts)+(T(9,1)-Ts)+(T(10,1)-Ts)+(T(11,1)-Ts)+(T(12,1)-Ts)+(T(13,1)-Ts)+(T(14,1)-Ts)+(T(15,1)-Ts)+(T(16,1)-Ts)+(T(17,1)-Ts)+(T(19,1)-Ts)+(T(20,1)-Ts)+(.5*T(I,1)-Ts)]

Homework Statement





Homework Equations





The Attempt at a Solution

 

Answers and Replies

  • #2
21
0
And what are your units?

On an aside, it's so warm in my room - it's like 28. And it's been warm for a while too - for almost 4 now. I tried to cool things down a bit by opening a gap in my window - a gap of 2.

Now - good luck deciphering that.

And then they wonder why nobody wants to hire american engineers anymore.
 
  • #3
35,285
7,132
I added [ code ] and [ /code ] tags (without extra spaces).
Hi so i have a heat transfer project to determine the material (aka the thermal conductivity) and length of a 2d wall. It has to have between -1 and 1 net rate of heat loss from the southern side and above 145 rate of heat transfer from the eastern side. The wall is 20 cm high na the boundry conditions are given in the code....
#1 I cannot find a material/length combo that satisfys the Q rateconditions so i wonder if my code is wrong?I was really unsure of how to do the equations for the heat rate of the specified sides, how do you find the heat rate of a given side with nodal temps known, heat conduction and convection?
#2 I have to plot the temp in the wall as a function of x position for y=0,10 an 20cm...how would i do this....
Heres the code i wrote so far
Code:
%Heat Transfer Project
%Material chosen was:
%Length Chosen was:
%Inputs, Given Values in degrees C, m, and 
Tn=100;
hn=20;
Te=20;
he=15;
Ts=70;
hs=30;
Tw=40;
hw=20;
H=0.2;
L=.5;
k=0.14;
I=21;
J=21;

%Geometry
deltax=L/(I-1);
deltay=L/(J-1);
x=[0:0.1:L];
y=[0:0.1:H];
A=L*H;
%Iterative loop
T=ones(I,J)*Tw;
Dum=1;
while Dum==1
    Told=T;
%Numeric Equations
%Interior Control Volumes
for i=2,I-1;
    for j=2,J-1;
        T(i,j)=(k*deltay*T(i-1,j)+k*deltay*T(i+1,j)+k*deltax*T(i,j-1)-k*deltax*T(i,j+1))/(2*k*deltay+2*k*deltax);
    end
end

%West & East sides
for j=2,J;
    T(1,j)=(-hw*deltay*Tw-(k*deltax)/(2*deltay)*T(1,j+1)-(k*deltax)/(2*deltay)*T(1,j-1)-(k*deltay)/deltax*T(2,j))/(-hw*deltay-2*((k*deltax)/(2*deltay))-(k*deltax)/(deltay));
    T(I,j)=(-he*deltay*Te-(k*deltax)/(2*deltay)*T(I,j+1)-(k*deltax)/(2*deltay)*T(I,j-1)-(k*deltay)/deltax*T(I-1,j))/(-he*deltay-2*((k*deltax)/(2*deltay))-(k*deltax)/(deltay));
end

%South & North
for i=2,I;
    T(i,1)=(-hs*deltax*Ts-(k*deltay)/(2*deltax)*T(i+1,1)-(k*deltay)/(2*deltax)*T(i-1,1)-(k*deltax)/deltay*T(i,2))/(-hs*deltax-2*((k*deltay)/(2*deltax))-(k*deltay)/(deltax));
    T(i,J)=(-hn*deltax*Tn-(k*deltay)/(2*deltax)*T(i+1,J)-(k*deltay)/(2*deltax)*T(i-1,J)-(k*deltax)/deltay*T(i,J-1))/(-hn*deltax-2*((k*deltay)/(2*deltax))-(k*deltay)/(deltax));
end

%Four Coners
T(1,1)=((-hw*Tw*deltay)/2-(hs*Ts*deltax)/2-(k*deltay)/(2*deltax)*T(2,1)-(k*deltax)/(2*deltay)*T(1,2))/(-(hw*deltay)/2-(hs*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(I,1)=((-he*Te*deltay)/2-(hs*Ts*deltax)/2-(k*deltay)/(2*deltax)*T(I-1,1)-(k*deltax)/(2*deltay)*T(I,2))/(-(he*deltay)/2-(hs*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(1,J)=((-hw*Tw*deltay)/2-(hn*Tn*deltax)/2-(k*deltay)/(2*deltax)*T(2,J)-(k*deltax)/(2*deltay)*T(1,J))/(-(hw*deltay)/2-(hn*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
T(I,J)=((-he*Te*deltay)/2-(hn*Tn*deltax)/2-(k*deltay)/(2*deltax)*T(I-1,J)-(k*deltax)/(2*deltay)*T(I,J-1))/(-(he*deltay)/2-(hn*deltax)/2-(k*deltay)/(2*deltax)-(k*deltax)/(2*deltay));
%Check for convergence
Dum=0;
for i=1,I;
for j=1,J;
    if (abs((Told(i,j)-T(i,j))/T(i,j))>0.0000001)
        Dum=1;
    end
end
end
end

Qe=he*deltay*[(T(I,1)-Te)/2+(T(I,2)-Te)+(T(I,3)-Te)+(T(I,4)-Te)+(T(I,5)-Te)+(T(I,6)-Te)+(T(I,7)-Te)+(T(I,8)-Te)+(T(I,9)-Te)+(T(I,10)-Te)+(T(I,11)-Te)+(T(I,12)-Te)+(T(I,13)-Te)+(T(I,14)-Te)+(T(I,15)-Te)+(T(I,16)-Te)+(T(I,17)-Te)+(T(I,19)-Te)+(T(I,20)-Te)+(.5*T(I,J)-Te)]
Qs=hs*deltax*[(T(1,1)-Ts)/2+(T(2,1)-Ts)+(T(3,1)-Ts)+(T(4,1)-Ts)+(T(5,1)-Ts)+(T(6,1)-Ts)+(T(7,1)-Ts)+(T(8,1)-Ts)+(T(9,1)-Ts)+(T(10,1)-Ts)+(T(11,1)-Ts)+(T(12,1)-Ts)+(T(13,1)-Ts)+(T(14,1)-Ts)+(T(15,1)-Ts)+(T(16,1)-Ts)+(T(17,1)-Ts)+(T(19,1)-Ts)+(T(20,1)-Ts)+(.5*T(I,1)-Ts)]

Homework Statement





Homework Equations





The Attempt at a Solution

 

Related Threads on MATLAB Code help Heat transfer

  • Last Post
Replies
2
Views
5K
  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
0
Views
8K
  • Last Post
Replies
0
Views
8K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
14
Views
4K
  • Last Post
Replies
1
Views
6K
Replies
0
Views
13K
Top