%
% Example 4.3B: Complex Fermentation Process
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
%
function dxdt = F4_3B( 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) );
  tau = p(15);
  %
  dxdt = zeros( 11, 1 );
  dxdt(1) = 0;
  dxdt(2) = - hydinsol + ( 350 - x(2) ) / tau;
  dxdt(3) = - hydsol + p(8) * x(5) + ...
     p(9) * x(10) + p(10) * x(11) ...
      + ( 150 - x(3) ) / tau;
  dxdt(4) = - hydon + ( 25 - x(4) ) / tau;
  dxdt(5) = p(14) * ( hydinsol + hydsol ) - p(8) * x(5) ...
      + ( 0 - x(5) ) / tau;
  dxdt(6) = ( 1 - p(14) ) * ( hydinsol + hydsol ) - gracid ...
       + ( 25 - x(6) ) / tau;
  dxdt(7) = hydon - p(13) * p(11) * gracid ...
       - p(13) * p(12) * grmeth ...
       + p(13) * ( p(9) * x(10) + p(10) * x(11) ) ...
       + ( 0 - x(7) ) / tau;
  dxdt(8) = ( 1 - p(11) ) * gracid - grmeth ...
       + ( 50 - x(8) ) / tau;
  dxdt(9) = ( 1 - p(11) ) * grmeth + ( 0 - x(9) ) / tau;
  dxdt(10) = p(11) * gracid - p(9) * x(10) + ( 0 - x(10) ) / tau;
  dxdt(11) = p(12) * grmeth - p(10) * x(11) + ( 0 - x(11) ) / tau;
%
%-----------------------------------------------------------
% the end!   
