%Brute force method 
clear all; close all; clc;
global coldata dyndata hydraulic alfa

% COLUMN DATA %%
% Number of stages in each section (C11,C12,C21,C22,C23,C24)
coldata.Nt = [12 12 12 12 12 12];
% Initial holdup in reboiler and condenser
coldata.M0 = [1 1 1 1 1 1 1 1 1 1 1 1];
%Boiling points of ethanol, propanol and n-butanol
coldata.Tboil = [78.37 97 117.4];
%Hydraulics
hydraulic.k1 = 1/0.063;

%Relative volatilit of Ethanol, Propanol and n-Butanol with respect to the
%heaviest n-Butanol
alfa=[4.215374389 2.102194688 1];
load Nominal_final
dyndata.x_nom = x_nom;
dyndata.u_nom = u_nom;

%dyndata.temp_nom = temp_nom;


% All the equality and inequality linear constraints are given in the file
%Specs
cost_F=zeros(1,9);                          % Vector of V-values with the different CVs kept constant
for i=1:9
    dyndata.u_nom(6)=(u_nom(6)*0.9):0.025:(u_nom(6)*1.1);     % Vector of F-values
    Specs
    
    beq(1)=dyndata.u_nom(6) ;                     % Keeping F at a ith value
    ptions = optimset('fmincon');
options = optimset(options,'TolFun',1e-10,'TolCon',1e-13,'MaxFunEvals',500000,'Display','iter',...
'Algorithm','active-set');%, 'GradObj','on','Hessian','on');%,..
    
    [x_opt,fval,exitflag,output,lambda,Grad,Hessian] = fmincon(@(x) Objective(x),[x_nom;u_nom],Ain,bin,Aeq,beq,[],[],@(x) Petlyuk_nonlcon(x),options);

x_nom=x_opt(1:225);u_nom=x_opt(226:end);

dxdt = norm(Petlyuk_NLmodel(0,x_nom, u_nom));

xf=x_nom;

    cost_F(i)=fval;                  % Cost with CV constant
end


% Optimization command 


