TADmech
Mechanical
- Jan 21, 2005
- 2
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