function [T HE] = tempCalc2(T0,w0,UA1,UA2,UA3,...
    Th1in,Th2in,Th3in,wh1,wh2,wh3,u)

w1 = u*w0;
w2 = (1-u)*w0;

NTU1 = UA1/w1;
NTU2 = UA2/w2;
NTU3 = UA3/w1;

C1 = w1/wh1;
C2 = w2/wh2;
C3 = w1/wh3;

if(C1>0.99999 && C1<1.00001)
    C1=0.99999;
end

if(C2>0.99999 && C2<1.00001)
    C2=0.99999;
end

if(C3>0.99999 && C3<1.00001)
    C3=0.99999;
end

e1 = (1-exp(-NTU1*(C1-1)))/(C1-exp(-NTU1*(C1-1)));
e2 = (1-exp(-NTU2*(C2-1)))/(C2-exp(-NTU2*(C2-1)));
e3 = (1-exp(-NTU3*(C3-1)))/(C3-exp(-NTU3*(C3-1)));

eh1 = e1*C1;
eh2 = e2*C2;
eh3 = e3*C3;

T1  = e1*Th1in + (1-e1)*T0;
T2  = e2*Th2in + (1-e2)*T0;
T3  = e3*Th3in + (1-e3)*T1;

Th1 = (1-eh1)*Th1in + eh1*T0;
Th2 = (1-eh2)*Th2in + eh2*T0;
Th3 = (1-eh3)*Th3in + eh3*T1;

Tmix = u*T3+(1-u)*T2;

T = [T1 T2 T3 Th1 Th2 Th3 Tmix];
HE = [e1 eh1 e2 eh2 e3 eh3 C1 C2 C3 NTU1 NTU2 NTU3];