function c=objfunct(u)
%Refrigeration section objective function
global hy,global hycase, global f,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' to give newinput u
%C3=compressor RPM, C4=HEX CW flow rate C128, C5=HEX CW flow rate C127ABCEF
    usprd=hyspread(hy,'Input');
    uc=hycell(usprd, {'B2','B3','B4','B5'});
%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~=0
    %Do nothing
    end
%Connect to Hysys spreadsheet 'CostFunc' for cost c
    csprd=hyspread(hy,'CostFunc');
    c=hyvalue(hycell(csprd, {'A2'}));
end




    


    
    