%
% Example 4.8: Compartmental Clarifier Model
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
%
function dxdt = Compartment_Clarifier( t, x )
global p
%
% x = [ 1=Mc 2=Ms 3=Xs ];
% p = [ 1=Vol 2=alpha 3=Ks 4=Kc 5=Kt ];
%
%-----------------------------------------------------------
  dist = 1;
%
  qf = 450;
  xf = 5390;
  qu = 200;
%
  if dist == 1,
    if t > 1 & t < 2,
      qf = 700;
    else
      qf = 450;
    end;
  end;
  if dist == 2,
    if t > 1 & t < 3,
      qu = 100;
    else
      qu = 200;
    end;
  end;
% sludge blanket volume
  vs = x(2) / x(3);
% overflow concentration
  xo = x(1) / ( p(1) - vs );
%
  dxdt = zeros( 3, 1 );
  dxdt(1) = p(2) * qf * xf ...
                - ( qf - qu ) * xo ...
                - p(3) * xo;
  dxdt(2) = ( 1 - p(2) ) * qf * xf ...
                - qu * p(4) * x(3) ...
                + p(3) * xo;
  dxdt(3) = ( ( 1 + x(2) / p(5) ) * xf - x(3) ) / ...
                ( x(2) / ( 1 - p(2) ) / qf / xf );
%
%-----------------------------------------------------------
% the end!   
