%
% Feedback Control Simulation
%
% Process: denitrification
% Controller: DMC
%
% Bob Newell, November 1997
%
%----------------------------------------------------------
% initialize dmc
%
global dynmat kpred predvect delt nextt nextu lastu law
%
delt = 10;
lastu = 0.5;
np = 30;
nu = 10;
yo = 0.5;
qd = 1*ones(np,1);
rd = 0.1*ones(nu,1);
%
nextt = -delt;
nextu = lastu;
predvect = yo * ones(np,1);
load dmc;
dynmat = a(:,1:nu);
q = diag( qd, 0 );
r = diag( rd, 0 );
kpred = inv( dynmat' * q * dynmat + r ) * dynmat' * q;
%
%----------------------------------------------------------
% initial state values
%
xo(1) = 0.480555;       % carbon dosage
xo(2) = 1.0;            % effluent substrate concentration (mg/l)
xo(3) = 2;              % cod effluent concentration (mg/l)
xo(4) = 0.5;            % nitrate sensor output
xo(5) = 0;              % error integral
%
%----------------------------------------------------------
%  integration
%
maxtime = 480;
%
law = 1;
[ t, x ] = ode23( 'dmc_function', [ 0 maxtime ], xo );
%
h = figure;
[ ha, h1, h2 ] = plotyy( t, x(:,4), t, x(:,1) );
set( h1, 'linestyle', '--' );
set( h2, 'linestyle', '--' );
axesyy( ha, [ 0 maxtime -1 1 0 2 ], ...
   'Time in minutes', ...
   'Sensor signal', ...
   'Carbon dosage', 2, ...
   [ 0 0.5 1 ], [ 0 0.5 1 ] );
%
law = 2;
[ t, x ] = ode23( 'dmc_function', [ 0 maxtime ], xo );
%
hold on;
plot( t, x(:,4) );
plot( t, x(:,1)-1 );
hold off;
%
arrow( [ 150 0.35 ], [ 150 0.57 ] );
h = text( 100, 0.25, 'predictive control' );
set( h, 'fontsize', 16 );
arrow( [ 350 0.65 ], [ 350 0.3 ] );
h = text( 325, 0.75, 'PI control' );
set( h, 'fontsize', 16 );
hold off;
%
%printsto -f1 -deps2 fig18-7b.eps
%
%----------------------------------------------------------
% the end
