%Petlyuk stabilized LV model
function xprime=Petlyuk_lv(t,x) 
%OR CS1
global UU dyndata tend  i
indmat_Yes_S1
L=1.398616622;
VB=1.73186;
Rl= 0.382737297;
RV= 0.587419639;
S1=0.33385308;
F=1;
zF=[0.333 0.333]';
qf=1;
%D=0.333243378;                                    % *1.04;
%B=0.332903542;

% P-Controllers for control of reboiler and condenser hold up.
KcB=10;  KcD=10;         % controller gains
MDs=19.37129893; MBs=19.21482825;       % Nominal holdups - these are rather small  
Ds=0.333243378;    Bs=0.332903542;         % Nominal flows
MB=x(im_mr);  MD=x(im_mt); % Actual reboiler and condenser holdup
D=Ds+(MD-MDs)*KcD;       % Distillate flow
B=Bs+(MB-MBs)*KcB;       % Bottoms flow     


U(1)=L;U(2)=VB;U(3)=Rl;U(4)=RV;U(5)=S1;U(6)=F; U(7:8)=zF;U(9)=qf;U(10)=D;U(11)=B;


if(t>0.01 || rem(i,10)==0) || t==tend
%     t
UU=[UU; t [L;VB;Rl;RV;S1;dyndata.u_nom(6:9); D; B;]'];

end
i=i+1;

%     t
xprime=Petlyuk_dxdt(t,x(1:end),[L;VB;Rl;RV;S1;dyndata.u_nom(6:9); D; B ]);