function [g,dg]=Objective(Var)
% Optimization objective 
% g  :objective to be minimized
% dg :gradient of g at var

GlobalVars;

Ix=IxConstr(1);
IxRON  = Ix(1);      RON  = Var(IxRON);    % Reformate RON
IxH2HC = Ix(2);      H2HC = Var(IxH2HC);   % H2HC ratio in reactor feed
IxmFi  = Ix(3);      mFi  = Var(IxmFi);    % Feed mass flow
IxmFC  = Ix(4);      mFC  = Var(IxmFC);    % Compressor mass flow
IxmFG  = Ix(5);      mFG  = Var(IxmFG);    % Gas product mass flow
IxmFR  = Ix(6);      mFR  = Var(IxmFR);    % Reformate mass flow
IxmFH  = Ix(7);      mFH  = Var(IxmFH);    % Hydrogen mass flow

Ix=IxHtr(1);       % Heater duty 
IxQ1 = Ix(1);       Q1 = Var(IxQ1);
Ix=IxHtr(2);       % Heater duty 
IxQ2 = Ix(1);       Q2 = Var(IxQ2);
Ix=IxHtr(3);       % Heater duty 
IxQ3 = Ix(1);       Q3 = Var(IxQ3);
Ix=IxHtr(4);       % Heater duty 
IxQ4 = Ix(1);       Q4 = Var(IxQ4);

Ix=IxCmp(1);       % Compressor work
IxW = Ix(1);       W = Var(IxW);

p=zeros(size(Var));

% Economy function (profit)
p(IxmFi) =  -60.0;
p(IxmFR)=   65.0;
p(IxmFG)=    50.0;
p(IxmFH)=   -50.0;

p(IxQ1) = -0.015;
p(IxQ2) = -0.015;
p(IxQ3) = -0.015;
p(IxQ4) = -0.015;
p(IxW)  = -0.015;

if Unscaled
   So=0.5;   
else
   So=2.0;
end
So=0.0001;

g=-So*p'*Sv*Var;                    % Objective
if nargout > 1
   dg=-So*Sv*p;
end

return         
