Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: MATLAB Code help Heat transfer

  1. May 22, 2010 #1
    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)]
    1. The problem statement, all variables and given/known data



    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Jun 15, 2011 #2
    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.
     
  4. Jun 15, 2011 #3

    Mark44

    Staff: Mentor

    I added [ code ] and [ /code ] tags (without extra spaces).
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook