function out = InternalHX(x, aux)
u = aux.u;
sc = aux.sc;
d = aux.d;
x = x.*sc.x;

T1 = x(1:d.nihx);
N1 = x(d.nihx+1:2*d.nihx);
Q = x(2*d.nihx+1:3*d.nihx);
T2 = x(3*d.nihx+1:4*d.nihx);
N2 = x(4*d.nihx+1:5*d.nihx);
A = x(end);

hinlet1 = u(1);
P1 = u(2); 
hinlet2 = u(3);
P2 = u(4);
n = u(5);


P2_tmp=[];P1_tmp=[];
for i=1:d.nihx
  h2(i, 1) = [h_given_TVN([T2(i); d.Vihx2/d.nihx; N2(i)])];
  h1(i, 1) = [h_given_TVN([T1(i); d.Vihx1/d.nihx; N1(i)])];
  P1_tmp = [P1_tmp; P_given_TVN([T1(i); d.Vihx1/d.nihx; N1(i)])];
  P2_tmp = [P2_tmp; P_given_TVN([T2(i); d.Vihx2/d.nihx; N2(i)])];
end
hin1 = [hinlet1; h1(1:end-1)];
hout1 = h1;
hin2 = [h2(2:end); hinlet2];
hout2 = h2;

out = [Q - n*(hin1-hout1);
       Q + n*(hin2-hout2);
       Q - d.Uihx*A/d.nihx*(T1-T2);
       P1 - P1_tmp;
       P2 - P2_tmp]./sc.res;
