function [c,ceq] = constraints(u)
%Constraints Function to pass inequality c and equality constraints ceq 
%from HYSYS to MATLAB solver fmincon
global hy, global hycase, global lb, global ub 
%(de)Scale input from MATLAB (0-1) to HYSYS bounded values    
    u=udescale(u,lb,ub);
%Connection to HYSYS spreadsheet 'Input' for input u
    usprd=hyspread(hy,'Input');
    uc=hycell(usprd,{'B2','B3','B4','B5','B6','B7','B8','B9'});
%Set HYSYS solver on hold,pass new input, activate solver
    hycase.solver.CanSolve=0;
    hyset(uc,u)
    hycase.solver.CanSolve=1;
%Solve for new input
    while hycase.Solver.issolving
    %Do nothing
    end
%Connection to HYSYS spreadsheet 'Constraints'
    consprd=hyspread(hy,'Constraints');
    c=hyvalue(hycell(consprd,{'A8','A9','A10','A11'}));
    ceq=[];%hyvalue(hycell(consprd,{'A2','A5'}));
end

