function xprime=multicomAP_lv(t,X) 
% sample usage:   [t,x]=ode15s('multicomA_lv',[0 20000],0.5*ones(1,NC*NT));
% keep record of results: lengthx=size(x); Xinit=x(lengthx(1),:)';

% multicomA_lv - Subroutine for simulation with LV-configuration.
%           It calls the model multicomA, and 
%           includes control of condenser and reboiler level 
%           using two P-controllers with the LV-configuration. 
%
%           Inputs are reflux (LT) and boilup (VB). Disturbances
%           are feedrate and feed composition. These are set by directly
%           altering 'multicomA_lv.m'. Outputs are liquid compositions 
%           for light and intermediate components and
%           liquid hold up for stages 1 through NT, given in x. 

% Number of stages in the column
NT=48;
%Number of components
NC=5;
% Inputs and disturbances
%LT=42.7;                          % Reflux
LT=27.1;
%VB=32.3;                       % Boilup
VB=33.865;
F=29.4;% Feedrate
%F=40;
qF=0.645;                              % Feed liquid fraction

zF=[0.01817636 0.57980319 0.09425689 0.18950644 0.11825622];% Feed compositions for component A to component NC 
%% P-Controllers for control of reboiler and condenser hold up.
%%
KcB=0.05;  KcD=0.02;                     % controller gains
MDs=227; MBs=38;                     % Nominal holdups - these are rather small  
%Ds=25.9; Bs=14.1;                    % Nominal flows
%Ds=21.1; Bs=8.3;                    
Ds=17.8; Bs=11.6; 
MB=X((NC-1)*NT+1);  MD=X(NC*NT);     % Actual reboiler and condenser holdup
D=Ds+(MD-MDs)*KcD;                   % Distillate flow
B=Bs+(MB-MBs)*KcB;                   % Bottoms flow     
% Store all inputs and disturbances
U(1)=LT; U(2)=VB; U(3)=D; U(4)=B; U(5)=F; U(6)=qF; A=zF; U=[U A];

xprime=multicomAP_matlab(t,X,U);

