% tube-in-tube countercurrent heat exchanger
% basic data
% tubes
doin = 1 ; % in
do = doin * 0.0254 ; % m
Ao = pi*do ; % m2/m
diin = 0.76 ; % in
di = diin * 0.0254 ; % m
Ai = pi*di ; % m2/m
L = 5 ; % m
% fluid properties
den = 998 ; % kg/m3
cP = 4187 ; % J/(kg*degC)
% heat transfer coefficients
hi = 14000 ; % W/(m2*degC)
ho = hi*di/do ; % W/(m2*degC)
% flow rates
qcL = 0.3 ; % L/s
qc = qcL/1000 ; % m3/s
wc = qc*den ; % kg/s
qhL = 1 ; % L/s
qh = qhL/1000 ; % m3/s
wh = qh*den ; % kg/s
% inlet temperatures
Tci = 10 ; % degC
Thi = 50 ; % degC
% initial estimate
Tho = 40 ; % degC
% anonymous function
solveODEsanon = @(Tho) solveODEs(Tho,hi,ho,Ai,Ao,L,wc,wh,cP,Tci,Thi);
% call fzero
Tho = fzero(solveODEsanon,Tho)
% solve model again
% z values
zspan = linspace(0,L) ;
% initial conditions
T0 = [ Tci Tho ]';
% anonymous function
htexranon = @(z,T) htexr(z,T,hi,ho,Ai,Ao,wc,wh,cP);
% solve ODEs
[ zsoln, Tsoln ] = ode45(htexranon,zspan,T0);
% unpack temperatures
Tcsoln = Tsoln(:,1);
Thsoln = Tsoln(:,2);
% create plot
plot(zsoln,Tcsoln,'b-',zsoln,Thsoln,'r-')
grid
xlabel('Distance - m')
ylabel('Temperature - degC')
legend('Cold stream','Hot stream','Location','southeast')
