%
% Example 4.3B: Complex Fermentation Process
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
%
function dxdt = Complex_Fermentation( t, x )
global p
%
% x = [ 1=V 2=Xs 3=Ss 4=Xon 5=Xe 6=Sf 7=Snh
%                 8=Sa 9=CH4 10=Xh 11=Xm ];
% p = [ 1=Khxs 2=Khs 3=Khn 4=muhatf 5=Kf 6=muhatm 7=Km
%       8=de 9=dh 10=dm 11=Yh 12=Ym 13=Ynx 14=Ye ];
%
%-----------------------------------------------------------
%
  hydinsol = p(1) * x(2) * x(5);
  hydsol = p(2) * x(3) * x(5);
  hydon = p(3) * x(4) * x(5);
  gracid = p(4) * x(6) * x(10) / ( p(5) + x(6) );
  grmeth = p(6) * x(8) * x(11) / ( p(7) + x(8) );
  %
  dxdt = zeros( 11, 1 );
  dxdt(1) = 0;
  dxdt(2) = - hydinsol;
  dxdt(3) = - hydsol + p(8) * x(5) + ...
                       p(9) * x(10) + p(10) * x(11);
  dxdt(4) = - hydon;
  dxdt(5) = p(14) * ( hydinsol + hydsol ) - p(8) * x(5);
  dxdt(6) = ( 1 - p(14) ) * ( hydinsol + hydsol ) - gracid;
  dxdt(7) = hydon - p(13) * p(11) * gracid ...
              - p(13) * p(12) * grmeth ...
              + p(13) * ( p(9) * x(10) + p(10) * x(11) );
  dxdt(8) = ( 1 - p(11) ) * gracid - grmeth;
  dxdt(9) = ( 1 - p(11) ) * grmeth;
  dxdt(10) = p(11) * gracid - p(9) * x(10);
  dxdt(11) = p(12) * grmeth - p(10) * x(11);
%
%-----------------------------------------------------------
% the end!   
