function [T1 Th1] = tempCalc(T0,Th1in,wc,wh,UA,n)

Cmin = min(wc,wh);
Cmax = max(wc,wh);

Cr = Cmin/Cmax;

NTU  = UA/Cmin;
NTU1 = NTU/n;

scr=sqrt(1+Cr^2);
a=1+exp(-NTU1*scr);
b=1-exp(-NTU1*scr);

e1 = 2/(1+Cr+scr*a/b);
    
%For only one shell pass    
if(n==1)
    e=e1;
end

%For n>1 Shell passes
if(n>1)
    x = ((1-e1*Cr)/(1-e1))^n-1;
    y = ((1-e1*Cr)/(1-e1))^n-Cr;
    
    e = x/y;
end

% Cold temperature out
T1 = Cmin/wc*e*Th1in + (1-Cmin/wc*e)*T0;

% Hot temperature out
Th1 = (1-Cmin/wh*e)*Th1in + Cmin/wh*e*T0;