I've written a code to calculate three numbers for me, however with the first for loop it takes forever to run compared to without it. I know it is over a large range but I was wondering if there was anyway to speed it up?
C_pd = Specific_Heat(T_d,X_d);C_pb = Specific_Heat(T_b,X_b);e = 0.1;f = e;g = 0.01;i = 1;k = 0;l = 100;m = k;n = l;for j=1:3 for T_f = k:e:l C_pf = Specific_Heat(T_f,X_f); a = M_f*C_pf*(T_f-T_cw); for T_o = m:f:n b = M_d*C_pd*(T_d-T_o) + M_b*C_pb*(T_b-T_o); if abs(a-b)<g T(1,i) = T_f; T(2,i) = T_o; i=i+1; end end end k = min(T(1,:)); l = max(T(1,:)); m = min(T(2,:)); n = max(T(2,:)); e = e/10; f = f/10; g = g/10;end
The idea of this code is to calculate the three variables, starting with a range of 0:100 until they converge. I know the answers are supposed to be T_f = 68 and T_o = 36 however am currently getting no where near those as it is taking too long to converge.
Thanks in advance
Best Answer