global dyndata

indmat_Yes_S1
%by loading Nominal 44 we got the nominal points and then we saved it in
%Nominal45. Now we can fix Rv corresponding to Nominal 45 and also xD1,C
%=0.003 and see the optimized value
%Nominal46 and 47 have exactly same value and they are values corresponding
%to minimum objective functions
%Now we have fixed RV i.e. Aeq(7,4) and after optimization again we got the
%same result

Nz = size([dyndata.u_nom;dyndata.x_nom]);% all decision variables including inputs U and compositions and holdup on stages

%Feed rate, composition & quality
Nv=7;
Aeq=zeros(Nv,Nz);beq=zeros(Nv,1); %linearity constraints where Ns are product/feed specifications
% Ain=-eye(4,Nz);bin=zeros(4,1);

% These are the values of only As which contributes in specifications and
% thus=1 and not 0. 
% Also all disturbances are numbered in order , dd1,dd2,dd3,dd4,dd5
Aeq(1,im_mS1+6)=1;               %feed flow rate, F (im_mS1+6), 231
Aeq(2,im_mS1+7)=1;               %composition of A in the feed, zF, (im_mS1+7),232
Aeq(3,im_mS1+8)=1;               %composition of B in the feed, zF, im_mS1+8),233
Aeq(4,im_mS1+9)=1;               %feed liquid fraction qf, (im_mS1+9),234
Aeq(5,im_mS1+2)=1;               %Boilup, Vmax, (im_mS1+4), 227
%Aeq(5,im_xt(2))=1;
%Aeq(6,im_xr(2))=1;
%Aeq(7,im_xS1(1))=1;
%Aeq(7,im_xS1(2))=1;

%beq(1:4)=dyndata.u_nom([6:9]);
beq(1)=dyndata.u_nom(6)*1;       %Feed flow rate value (dd1)
beq(2:4)=dyndata.u_nom(7:9);     %Feed composition values (dd2,dd3)
beq(5)=1.73186;                  %The value of boilup Vmax (fixed)(dd4)
Aeq (6,im_x1(1))=1;              % A in D1 (Prefrac top)                        
Aeq(6,im_x1(coldata.Nt(1)+1))=1; % B in D1 (Prefrac top)                                    %11+im_x1(coldata.Nt(1)+1))=1;
beq(6)=1-0.003;                  % C in D1 is (1-sum(A,B)) (This means active constraint)
%Aeq(7,47)=1;                                       
%beq(7)=0.0015;% 
Aeq(7,im_mS1+4)=1;                % RV           
beq(7)=0.587419691;               % The value of vapor split ratio which is fixed (dd5)
%corresponding values of equality constraints.
%beq(5)=0.005;
%beq(6)=0.005;
%beq(7)=0.0005;
%beq(7)=0.99;
% Levels, totally unnecessary constraints

%Aeq(5,11+im_mt)=1;beq(5)=x_nom(im_mt);% im_mt=368+11=379 position in x_nom means condenser hold up
%Aeq(6,11+im_mr)=1;beq(6)=x_nom(im_mr);%im_mr=367+11=378(As)...367 is w.r.t. only x_nom but
%378 is when Uadded 11.fixing reboler hold up to 19.8541

%%%%%%%%%%
Ain=-eye(Nz,Nz);bin=zeros(Nz,1);%Non-negativity of state, helps optimizer
%Ain=eye(Nz+1:Nz+150,12:11+im_xS1(2));bin=ones(12:11+im_xS1(2));
%inequality constraints, setting lower and upper bounds, - signs -eye sets
%bound on all input and state vectors should be greater than 0
%Ain=-eye(2*Nz+4,11+);bin=-ones(2*Nz+4,1); %Non-negativity of state, helps optimizer
%Ain(Nz+1:Nz+150,11+im_x1:11+im_xS(2))=
%Compostion constraints (3) as in the paper
%Vmax=1.5544;


%Ain(Nz+1,11+im_xt(2))=1;bin(Nz+1)=0.005;
%Ain(Nz+2,11+im_xS1(1))=1;bin(Nz+2)=0.0005;

%Ain(Nz+3,11+im_xr(2))=1;
%bin(Nz+3)=0.005;

%Ain(Nz+4,11+im_xS1(1))=-1;
%Ain(Nz+4,11+im_xS1(2))=-1;
%bin(Nz+4)=-(1-0.0005-0.005);



