%
% Example 3.5: DO Controller
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
%
function dxdt = DO_Controller( t, x )
global p
%
% x = [ 1=V 2=Ss 3=So 4=z ];
% y = [ 1=v_in 2=Ss_in 3=So_in 
%       4=v_out 5=Ss_out 6=So_out
%       7=v_a ];
% p = [ 1=Ka 2=So_sat
%       3=yd 4=uo 5=Kc 6=taui ];
%
%-----------------------------------------------------------
  y = DO_Controller_Outputs( t, x );
  dxdt = zeros( 4, 1 );
%
  dxdt(1) = y(1) - y(4);
  dxdt(2) = ( y(1) * y(2) - y(4) * y(5) ) / x(1);
  dxdt(3) = ( y(1) * y(3) - y(4) * y(6) ...
           + p(1) * y(7) * ( p(2) - x(3) ) ) / x(1);
  dxdt(4) = p(3) - y(6);
%-----------------------------------------------------------
% the end!   
