% programa 16.4, luyben, pag. 587
% "Doyle-Stein criterion for Wood and Berry column"
% modif. E.Quintero.M 25mar'99
%-------------------------------------------------------
clear
format short e
% process transfer function data
kp=[12.8 -18.9; 6.6 -19.4]; xx=[];
n=2; D=[1 3; 7 3];
tau=[16.7 21; 10.9 14.4];
% empirical controller settings
kc=[.2 -.04]; reset=[4.44 2.67];
% set initial frequency and number of points per decade
w=0.01; dw=10^(1/20);
% main loop for each frequency
while(w<10)
   s=i*w;
   for j=1:n
      for k=1:n
         gm(j,k)=kp(j,k)*exp(-D(j,k)*s)/(tau(j,k)*s+1);
      end
   end
   b=zeros(n);
   for j=1:n
      b(j,j)=kc(j)*(reset(j)*s+1)/(reset(j)*s); 
   end
   q=gm*b;
   qin=inv(q);
   a=diag(diag(ones(n)))+qin;
   ceigen=eig(a'*a);
   sval=sqrt(real(ceigen));
   sval=sort(sval);
   xx=[xx;w 20*log10(sval)'];
w=w*dw;
end
semilogx(xx(:,1),xx(:,2),xx(:,1),xx(:,3)),grid
