function res = nonlcon(x, Prob)
d = Prob.d;
sc = Prob.sc;
u = Prob.u;
y = x.*sc.x;
Tcs = u(1);
Ths = u(2);

xcon = x(1:23);
xvap = x(27:33);
xval = x(24:26);
xcom = x(34:35);

ycon = y(1:23);
yvap = y(27:33);
yval = y(24:26);
ycom = y(34:35);

T = [ycom(2);ycon(1:5);yvap(1)];
n = yval(2);
Ph = ycon(23);
Pl = yvap(end);
h_to_valve = ycon(22)*d.Cpl*(T(6)-d.Tref)+(1-ycon(22))*(d.Cpg*(T(6)-d.Tref)+d.hvap);
yval(end);
rho_to_valve = ycon(22)*rhol(d)+(1-ycon(22))*rhov(ycon(5), Ph, d);
% Condenser
ucon = [T(1); n; Ths];
aux.sc=sc.con;
aux.d=d;
aux.u=ucon;
res_con = condenser(xcon, aux);
% Vaporizer
uvap = [n; Tcs; yval(end)];
aux.u=uvap;
aux.sc=sc.vap;
res_vap = vaporizer(xvap, aux);
% Valve
uval = [Ph-Pl; rho_to_valve; h_to_valve];
aux.u=uval;
aux.sc=sc.val;
res_val = valve(xval, aux);
% Compressor
ucom = [T(end); n; Ph; Pl];
aux.u=ucom;
aux.sc=sc.com;
res_com = compressor(xcom, aux);

res=[res_con; res_val; res_vap; res_com];
