function [T HE] = tempCalc3(T0,w0,UA11,UA1,UA2,UA3,Th11in,Th1in,Th2in,Th3in,wh11,wh1,wh2,wh3,u1,u2)

u3=1-u1-u2;

w1 = u1*w0;
w2 = u2*w0;
w3 = u3*w0;

NTU11 = UA11/w1;
NTU1  = UA1/w1;
NTU2  = UA2/w2;
NTU3  = UA3/w3;

C11 = w1/wh11;
C1  = w1/wh1;
C2  = w2/wh2;
C3  = w3/wh3;

if(C11>0.99999 && C11<1.00001)
    C11=0.99999;
elseif(C1>0.99999 && C1<1.00001)
    C1=0.99999;
elseif(C2>0.99999 && C2<1.00001)
    C2=0.99999;
elseif(C3>0.99999 && C3<1.00001)
    C3=0.99999;
end

e11= (1-exp(-NTU11*(C11-1)))/(C11-exp(-NTU11*(C11-1)));
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)));

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

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

Th11= (1-eh11)*Th11in + eh11*T0;
Th1 = (1-eh1)*Th1in + eh1*T11;
Th2 = (1-eh2)*Th2in + eh2*T0;
Th3 = (1-eh3)*Th3in + eh3*T0;

Tmix = u1*T1+u2*T2+u3*T3; 

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