%
% Example 14.6: Activated Sludge Aerobic Zone
%
% Batch formulation
%
% Simplified IAWQ No.2 Model assuming:
%  - C removal only
%  - biomass growth
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
%
function dxdt = Nitrifying_Aerobic_Zone( t, x )
global p
%
% x = [ 1=Sf 2=So2 3=Xh 4=Xs 5=Snh4 6=Sno3 7=Xa ];
% p = [ 1=muhath 2=Kla 3=Koh 4=Kf 5=Yh
%       6=muhata 7=Ko22 8=Knh 9=Ya ];
%
%-----------------------------------------------------------
  hydrate = 3.0 * x(4) / ( 0.1 + x(4) / x(3) );
  hetero = p(1) * x(1) * x(2) * x(3) ...
              / ( p(3) + x(2) ) / ( p(4) + x(1) );
  auto = p(6) * x(2) * x(5) * x(7) ...
              / ( p(7) + x(2) ) / ( p(8) + x(5) ) ;
  our = hetero * ( p(5) - 1 ) / p(5);
  nour = auto * ( p(9) - 4.57 ) / p(9);
%
  dxdt = zeros( 7, 1 );
  dxdt(1) = hydrate - hetero / p(5) ...
                  + 0.2 * x(3) + 0.135 * x(7);
  dxdt(2) = nour + our + p(2) * ( 7 - x(2) );
  dxdt(3) = hetero - 0.4 * x(3);
  dxdt(4) = - hydrate + 0.36 * x(3);
  dxdt(5) = - auto / p(9);
  dxdt(6) = auto / p(9);
  dxdt(7) = auto - 0.15 * x(7);
%
%-----------------------------------------------------------
% the end!   
