%
% Example 15.6a: Activated Sludge Anaerobic Zone
%
% Batch formulation
%
% Simplified IAWQ No.2 Model assuming:
%  - anaerobic hydrolysis, fermentation, P release
%  - biomass concentrations constant
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
%
function dxdt = open_loop_anaerobic_zone( t, x )
global p
%
% x = [ 1=Xs 2=Sf 3=Sa 4=Xpp 5=Spo4 ];
% p = [ 1=Khnfe 2=Kx 3=qfe 4=Kfe 
%       5=qpha 6=Ka 7=Kpp 8=Ypo4
%       9=Xh 10=Xpao ];
%-----------------------------------------------------------
  dxdt = zeros( 5, 1 );
  hydrate = p(1) * x(1) / ( p(2) + x(1) / p(9) ) / 24; 
  fermrate = p(3) * x(2) * p(9) / ( p(4) + x(2) ) / 24;
  relrate = p(5) * x(3) * x(4) / ( p(6) + x(3) ) ...
               / ( p(7) + x(4) / p(10) ) / 24;
  dxdt(1) = - hydrate;
  dxdt(2) = hydrate - fermrate;
  dxdt(3) = fermrate - relrate;
  dxdt(4) = - p(8) * relrate;
  dxdt(5) = p(8) * relrate;
%-----------------------------------------------------------
% the end!   
