%
% Example 12.3: Simple Biological Reactor
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
%
function dxdt = Simple_Biological_Reactor( t, x )
global p
%
% x = [ 1=V 2=Sn 3=Xb ];
% y = [ 1=v_in 2=Sn_in 3=Xb_in 
%       4=v_out 5=Sn_out 6=Xb_out  ];
% p = [ 1=muhat 2=Kn 3=Yb 4=Kfilter ];
%
%-----------------------------------------------------------
  y = Simple_Biological_Reactor_Outputs( t, x );
  dxdt = zeros( 6, 1 );
%
  mu = p(1) * y(5) * y(6) / ( p(2) + y(5) );
  dxdt(1) = y(1) - y(4);
  dxdt(2) = ( y(1) * y(2) - y(4) * y(5) ) / x(1) - mu / p(3);
  dxdt(3) = ( y(1) * y(3) - y(4) * y(6) ) / x(1) + mu;
%-----------------------------------------------------------
% Value of 400 for Figure 12-03
%      and 4000 for Figure 12-04
  k = - p(4);
  mu = p(1) * x(4) * x(6) / ( p(2) + x(4) );
  dxdt(4) = ( y(1) * y(2) - y(4) * x(4) ) / x(1) - mu / p(3);
  dxdt(5) = ( y(1) * y(3) - y(4) * x(6) ) / x(1) + mu;
  dxdt(6) = k * ( x(2) - x(4) );
%-----------------------------------------------------------
% the end!   
