function nonlinres = Brobekk_nonlincon(x,Prob)

% Parameters
p1B = Prob.p1B;         p1V = Prob.p1V;         rho_h = Prob.rho_h;
rho_c = Prob.rho_c;     Kv_HB = Prob.Kv_HB;     Kv_AC = Prob.Kv_AC;
Kv_HE = Prob.Kv_HE;     Tci = Prob.Tci;         Tci_air = Prob.Tci_air;
Thi_F = Prob.Thi_F;     w_fg = Prob.w_fg;       w_V = Prob.w_V;
eta_p = Prob.eta_p;     scx = Prob.scx;         scC = Prob.scC;
scCeq = Prob.scCeq;     UA_F = Prob.UA_F;       A_HE = Prob.A_HE;
A_AC = Prob.A_AC;       cp_air = Prob.cp_air;   cph = Prob.cph;
cpc = Prob.cpc;         z = Prob.z;             rho_air_c = Prob.rho_air_c;
A_f = Prob.A_f;         dp_f = Prob.dp_f;       eta_f = Prob.eta_f;

% De-scaling the variables
x = x.*scx;

% Variables written in symbolic form
uHB = x(1);         uAC = x(2);     uHE = x(3);
uCB = x(4);         uCI = x(5);     P_B = x(6);
P_V = x(7);         w_air = x(8);   P_f = x(9);
Tci_F = x(10);      w_B = x(11);

% =========================================================================
%                             SYSTEM EQUATIONS
% =========================================================================

% Calculating discharge pressures [bar]
% It is assumed that A1 = A2, and that dz = 0
p2B = p1B-(rho_h*P_B*eta_p/(w_B*10^5));
p2V = p1V-(rho_c*P_V*eta_p/(w_V*10^5));

% Calculating liquid flow rates [kg/s]
wCB = Kv_Viken(uCB)*sqrt((p1V-p2V)*(1000/rho_c))*(rho_c/3600);
wCI = Kv_Viken(uCI)*sqrt((p1V-p2V)*(1000/rho_c))*(rho_c/3600);

wHB = uHB*Kv_HB*sqrt((p1B-p2B)*(1000/rho_h))*(rho_h/3600);
wAC = uAC*Kv_AC*sqrt((p1B-p2B)*(1000/rho_h))*(rho_h/3600);
wHE = uHE*Kv_HE*sqrt((p1B-p2B)*(1000/rho_h))*(rho_h/3600);

% Calculating heat transfer coefficients [W/m2*K]
h_HE = hHE(wCI);
h_AC = hAC(w_air);

% Calculating UA numbers for the heat exchanger and air cooler under the
% assumption hh = hc
UA_HE = 0.5*h_HE*A_HE;
UA_AC = 0.5*h_AC*A_AC;

% Calculating furnace heat duty [W] and outlet temperatures [°C]
F = NTU_calc(Tci_F,w_B,Thi_F,w_fg,UA_F,cp_air,cph);

% Calculating heat exchanger heat duty [W] and outlet temperatures [°C]
HE = NTU_calc(Tci,wCI,F(2),wHE,UA_HE,cph,cpc);

% Calculating air cooler heat duty [W] and outlet temperatures [°C]
AC = NTU_calc(Tci_air,w_air,F(2),wAC,UA_AC,cph,cp_air);

% =========================================================================
%                     NONLINEAR INEQUALITY CONSTRAINTS
% =========================================================================
% Temperature towards Viken/Oslo
% Heat exchanger secondary side outlet temperature
% Heat exchanger primary side outlet temperature

C = [((wCB*Tci)+(2*wCI*HE(2)))/(wCB+(2*wCI));
     HE(2);
     HE(1)];

% =========================================================================
%                      NONLINEAR EQUALITY CONSTRAINTS
% =========================================================================
% Energy balance at Brobekk
% Mass balance at Brobekk
% Mass balance at Viken
% Water inlet temperature in furnace
% Air cooler fan

Ceq = [F(3) - HE(3) - AC(3);
       w_B - wHB - wAC - wHE;
       w_V - wCB - (2*wCI);
       Tci_F - ((wHB*F(2))+(wAC*AC(1))+(wHE*HE(1)))/(wHB+wAC+wHE);
       P_f - ((w_air^3)*(1-z)/(2*(rho_air_c*A_f)^2)+(w_air*dp_f/rho_air_c))/eta_f];

% Scaling C and Ceq
C = C./scC;
Ceq = Ceq./scCeq;

nonlinres = [C;Ceq];