%
% Example 9.4: Aerated Biological Reactor
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
%
function y = Aerated_Bioreactor_Outputs( t, x )
global p
%
% x = [ 1=V 2=Sn 3=So 4=Xb ];
% y = [ 1=v_in 2=Ss_in 3=So_in 4=Xh_in 
%       5=v_out 6=Ss_out 7=So_out 8=Xh_out
%       9=v_a  ];
% p = [ 1=muhat 2=Ks 3=Koh 4=Yh 5=bh 6=fp
%       7=Ka 8=So_sat ];
%
%-----------------------------------------------------------
  [ n, m ] = size( x );
  if m == 1,
    x = x';
    n = 1;
  end;
  y = zeros( n, 9 );
%
  for i = 1:n,
    % influent conditions
    y(i,1) = 5;
    y(i,3) = 1;
    y(i,4) = 110;
    if t(i) < 5/24,
      y(i,2) = 400;
      y(i,9) = 5;
    elseif t(i) < 10/24,
      y(i,2) = 400;
      y(i,9) = 20;
    else,
      y(i,2) = 300;
      y(i,9) = 20;
    end; 
    % constant volume
    y(i,5) = y(i,1);
    % well mixed
    y(i,6) = x(i,2);
    y(i,7) = x(i,3);
    y(i,8) = x(i,4);
  end;
%-----------------------------------------------------------
% the end!   
