%Specs Nullspace Method
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
%dd = 1e-5;
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=6;
Aeq=zeros(Nv,Nz);beq=zeros(Nv,1); %linearity constraints where Ns are product/feed specifications

% These are the values of only As which contributes in specifications and
% thus=1 and not 0. 

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

%beq(1:4)=dyndata.u_nom([6:9]);
beq(1)= dyndata.u_nom(6);       %Feed flow rate value (dd1)
beq(2)=dyndata.u_nom(7);       %Feed composition zA 
beq(3)=0.9*dyndata.u_nom(8);       %Feed composition zB
beq(4)=dyndata.u_nom(9);       % liquid feed
beq(5)=dyndata.u_nom(2);       %The value of boilup Vmax (fixed)(dd3)
Aeq(6,im_mS1+4)=1;                % RV           
beq(6)=dyndata.u_nom(4);          % The value of vapor split ratio which is fixed (dd5)

%Aeq (7,im_x1(1))=1;              % A in D1 (Prefrac top)                        
%Aeq(7,im_x1(coldata.Nt(1)+1))=1; % B in D1 (Prefrac top)                                    %11+im_x1(coldata.Nt(1)+1))=1;
%beq(7)=1-0.003;                  % C in D1 is (1-sum(A,B)) (This means active constraint)
%Aeq(7,47)=1;                                       
%beq(7)=0.0015;% 

%%%%%%%%%%
Ain=-eye(Nz,Nz);bin=zeros(Nz,1);%Non-negativity of state, helps optimizer







