function res=subcooling(x, d, Tin, Tout, n, Ths)
T=[Tin;x(1:3)];
A=x(4);

Qsub = d.Ucon(3)*A/3*(Ths-T(2:end));

res = [Qsub-n*d.Cpl*(T(2:4)-T(1:3));
       Tout-T(end)];
