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=[CW-2 flow,Split VLV-4, Comp speed, CW-3 Cooling, CW-4 Cooling,AC-2 RPM]
    usprd=hyspread(hy,'Input');
    uc=hycell(usprd, {'B2','B3','B4','B5','B6','B7'});
%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




    


    
    