%
% Function to calculate state derivatives for the
% simple carbon removal plant in Appendix B
%
% Bob Newell, January 1996
%
function dxdt = State_Derivatives( t, x )
%
global vt
%
% first calculate the growth rate
%
mu = vt(11) * x(1) / ( vt(12) + x(1) ) ...
                * x(2) / ( vt(13) + x(2) ) * x(3) ;
%
% substrate mass balance
%
dxdt(1) = vt(1) * ( vt(2) - x(1) ) / vt(9) ...
            - mu / vt(15) + ( 1 - vt(16) ) * vt(14) * x(3) ;
%
% oxygen mass balance
%
dxdt(2) = - vt(1) * x(2) / vt(9) ...
             + ( vt(15) - 1 ) * mu / vt(15) ...
			 + ( vt(17) * vt(5) + vt(18) ) * ( vt(10) - x(2) ) ;
%
% hetertrophs mass balance
%
dxdt(3) = - vt(4) * ( vt(1) + vt(3) ) * x(3) ...
                          / vt(9) / ( vt(4) + vt(3) ) ...
			 + mu - vt(14) * x(3) ;
%
return ;
