%
% Example 4.9: Carbon Removal in Batch Reactor
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
%
function dxdt = Batch_Reactor( t, x )
global p
%
% x = [ 1=V 2=Ss 3=So 4=Xh ];
% p = [ 1=muhat 2=Ks 3=Koh 4=Yh 5=bh 6=fp
%       7=a 8=b 9=So_sat ];
%
%-----------------------------------------------------------
% DO control
  qa = - 25 * ( x(3) - 3.0 );
  if qa > 25, qa = 25; end;
%
  mu = p(1) * x(2) * x(3) * x(4) / ( p(2) + x(2) ) ...
                         / ( p(3) + x(3) );
  kla = p(7) * ( 1 - exp( - qa / p(8) ) );
  dxdt = zeros( 4, 1 );
  dxdt(1) = 0;
  dxdt(2) = - mu / p(4) + p(5) * x(4) * ( 1 - p(6) );
  dxdt(3) = mu * ( p(4) - 1 ) / p(4) ...
                + kla * ( p(9) - x(3) );
  dxdt(4) = mu - p(5) * x(4);
%-----------------------------------------------------------
% the end!   
