% programa 16.2, W.L.Luyben, pag. 569
% "characteristic loci plots for Wood and Berry column"
% modif. E.Quintero.M 13nov'98
%-------------------------------------------------------
clear
format short e
% process transfer function data
kp=[12.8 -18.9; 6.6 -19.4];
n=2; D=[1 3; 7 3];
tau=[16.7 21; 10.9 14.4]; xx=[]; yy=[];
% empirical controller settings
for m=1:2
   if(m==1) kc=[.2 -.04]; reset=[4.44 2.67]; end
   if(m==2) kc=[0.96 -0.19]; reset=[3.25 9.20]; end
% set initial frequency and number of points per decade
w=0.01; dw=10^.1;
% main loop for each frequency
while(w<2.6)
   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;
   ceigen=eig(q);
%xx=[xx;w ceigen.'];
   if(m==1) xx=[xx;w ceigen.']; end
   if(m==2) yy=[yy;w ceigen.']; end
w=w*dw;
end
end
subplot(2,2,1),plot(xx(:,2)),grid,axis([-3 2 -2 2])
subplot(2,2,2),plot(xx(:,3)),grid,axis([-3 2 -2 2])
subplot(2,2,3),plot(yy(:,2)),grid,axis([-3 2 -2 2])
subplot(2,2,4),plot(yy(:,3)),grid,axis([-3 2 -2 2])