×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with code for heat transfer between two solid objects

Help with code for heat transfer between two solid objects

Help with code for heat transfer between two solid objects

(OP)
I am new to MATLAB and am having a little trouble. I have a relatively simple problem where I need to calculate the final temp of two contacting objects after approx 60 seconds, where T1 > T2. The code I have so far is very basic and does not allow input. I am trying to get it to work with to given values before I allow external, real-world input (where the time, initial temps, and heat capcities will be user specific).

I have listed the code that I have below hoping someone can provide a few pointers.

alpha = 1;
t = 0;              % time (seconds)
delta_t = 1;        % 1 second interval
Max_t = 60;         % maximum time

T1 = 100;           % deg C
m1 = 2;             % kg
c1 = 5;             % heat capacity

T2 = 20;            % deg C
m2 = 4;             % kg
c2 = 4;             % heat capacity

% Values of expression won't change - calculate prior to while loop
alpha_1 = ((alpha)*(delta_t))/(m1 * c1);
alpha_2 = ((alpha)*(delta_t))/(m2 * c2);

while (t < Max_t);
    t = t + delta_t
    T1 = (1 - alpha_1).*(T1) + (1-alpha_1).*(T2)
    T2 = (alpha_2).*(T1) + (1-alpha_2).*(T2)
end

plot (T1,t,T2,t,'--')

Thank you any help that you can provide in clearing up my MATLAB ignorance .

RE: Help with code for heat transfer between two solid objects

You are overwriting the values of T1 and T2 each time you go round the loop. You need to store these values in a vector. You also have a ";" at the end of the while statement which should not be there.

Can you clarify exactly what you are trying to do? I would suggest that for a simple calculation like this you could use some other software with which you are more familiar (C or Basic or even Excel for example) rather than trying to learn Matlab!

M

--
Dr Michael F Platten

RE: Help with code for heat transfer between two solid objects

(OP)
Thanks for your help. Unfortunately, it is an in-house initiative to use MATLAB. I shouldn't say unfortunately, it is a powerful program and it would benefit me to learn it. Just a little tough under these circumstances.

I have not found any documentation on storing a vector in a while loop. Most of my attempts have lead to the values still being overwritten. Can you point me in the right direction?

Thanks again.

RE: Help with code for heat transfer between two solid objects

I suggest you do some reading, eg "Mastering Matlab".

M

--
Dr Michael F Platten

RE: Help with code for heat transfer between two solid objects

I'd create a vector for t using the statement, then iterate through it with an indexed for loop, e.g.,

alpha = 1;

delta_t = 1;        % 1 second interval
Max_t = 60;         % maximum time
t = 0:delta_t:Max_t;

T1 = zeros(1,length(t));
T2 = zeros(1,length(t));

T1(1,1) = 100;      % deg C
m1 = 2;             % kg
c1 = 5;             % heat capacity

T2(1,1) = 20;       % deg C
m2 = 4;             % kg
c2 = 4;             % heat capacity

% Values of expression won't change - calculate prior to loop
alpha_1 = ((alpha)*(delta_t))/(m1 * c1);
alpha_2 = ((alpha)*(delta_t))/(m2 * c2);

for n = 1:length(t)
    T1(1,n+1) = (1 - alpha_1)*(T1(1,n)) + (1-alpha_1)*(T2(1,n));
    T2(1,n+1) = (alpha_2)*(T1(1,n)) + (1-alpha_2).*(T2(1,n));
end

I don't have MATLAB on the computer I'm using, but something like this should work. You may have to fiddle around with it a little. Oh, and your plot statement argument order seems backwards: plot(t,T1,T,T2,'--').

xnuke
"Do you think you used enough dynamite there, Butch?"
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources