%
% Example 6.2: Carbon Removal Process
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
%
function dxdt = Carbon_Removal( t, x )
global p
%
% x = [ 1=V 2=Sn 3=So 4=Xb ];
% p = [ 1=muhat 2=Ks 3=Koh 4=Yh 5=bh 6=fp
%       7=a 8=b 9=So_sat ];
%
%-----------------------------------------------------------
  qin = 50;
  ssin = 150;
  soin = 1;
  xhin = 5;
  qa = p(10);
  qr = 50;
  qw = p(11);
% constant volume
  qout = qin;
% well mixed
  ssout = x(2);
  soout = x(3);
  xhout = x(4);
%
  mu = p(1) * ssout * soout * xhout / ( p(2) + ssout ) ...
                         / ( p(3) + soout );
  kla = p(7) * ( 1 - exp( - qa / p(8) ) );
  dxdt(1) = qin - qout;
  dxdt(2) = qin * ( ssin - ssout ) / x(1) ...
                - mu / p(4) + p(5) * xhout * ( 1 - p(6) );
  dxdt(3) = ( qin * soin - ( qin + qr ) ...
                * soout ) / x(1) ...
                + mu * ( p(4) - 1 ) / p(4) ...
                + kla * ( p(9) - soout );
  dxdt(4) = ( qin * xhin - qw * ( qin + qr ) ...
                * xhout / ( qr + qw ) ) / x(1) ...
                + mu - p(5) * xhout;
%-----------------------------------------------------------
% the end!   
