%
% Example 18.9: Complex Fermentation Process
%
% - constant volume
% - well mixed
% - Monod kinetics
% - batch configuration
%
% Bob Newell, May 1996
%
%-----------------------------------------------------------
% parameters
Khxs = 0.5*0.1;
Khs = 3;
Khn = 3;
muhatf = 6;
Kf = 20;
muhatm = 0.8;
Km = 20;
de = 0.4;
dh = 0.4;
dm = 0.4;
Yh = 0.6;
Ym = 0.6;
Ynx = 0.01;
Ye = 0.01;
flow = 45; % m3/hr
volume = 800; % m3
tau = volume / flow;
%
global p
p = [ Khxs Khs Khn muhatf Kf muhatm Km ...
       de dh dm Yh Ym Ynx Ye tau ];
%-----------------------------------------------------------
% initial states
V = 12.5;
Xs = 350;
Ss = 150;
Xon = 25;
Xe = 10;
Sf = 25;
Snh = 0;
Sa = 50;
CH4 = 0;
Xh = 850;
Xm = 10;
%
xo = [ V Xs Ss Xon Xe Sf Snh Sa CH4 Xh Xm ];
%
xo = [ 12.5000  149.7631   12.0873    0.3078 ...
      1.0028    2.7669   23.9225 ...
      205.8851  126.5219   60.7075   16.2655 ];
%-----------------------------------------------------------
% integrate the state equation
to = clock;
days = 180;
[ t, x ] = ode45( 'anaerobic_reactor', [ 0 days ], xo );
secs = etime( clock, to )
%-----------------------------------------------------------
% plot the results
font = 16;
figure;
plot( t, x(:,2), t, x(:,8), t, x(:,9), t, x(:,11) );
set( gca, 'fontsize', font );
xlabel( 'Time in days' );
ylabel( 'Concentration in mg/l' )
%legend( 'Xs', 'Sa', 'CH4', 'Xm' );
%
h = text( 25, 25, 'Methanogens' );
set( h, 'fontsize', font );
h = text( 100, 45, 'Methane' );
set( h, 'fontsize', font );
h = text( 100, 180, 'Insoluble COD' );
set( h, 'fontsize', font );
h = text( 100, 260, 'VFAs' );
set( h, 'fontsize', font );
%
print -f1 -deps2 equal-tank.eps
%
%-----------------------------------------------------------
% the end!   
