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
.
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
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
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
M
--
Dr Michael F Platten
RE: Help with code for heat transfer between two solid objects
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.