%Example 6.8 Feedback control of distillation process, DV-model
%
clear all 
close all
w=logspace(-1,2,61);
%Model (6.87)
G0=[-87.8 1.4;-108.2 -1.4];
dyn = nd2sys(1,[75 1]); Dyn = daug(dyn,dyn); G = mmult(Dyn,G0);

%RGA(G)
Lambda=rga(G0)  

%Inverse-based controller
kdyn=nd2sys(1,[1 1e-6],0.7);
K=mmult(daug(kdyn,kdyn),inv(G0));

w1=0.2;w1f=frsp(w1,w);
w2=nd2sys([5 1],[0.5 1],0.2);w2f=abs(frsp(w2,w));
gamma=1.1096;
s=minv(madd(1,nd2sys(0.7,[1 0])));sf=abs(frsp(s,w));
t=msub(1,s);tf=abs(frsp(t,w));
wt1=mmult(w1,t);wt1f=abs(frsp(wt1,w));
wt2=mmult(w2,t);wt2f=abs(frsp(wt2,w));
L1=mmult(sf,madd(1,mmult(wt1f,minv(madd(1,wt1f)))));
L2=mmult(sf,madd(1,mmult(wt2f,minv(madd(1,wt2f)))));
U11=mmult(gamma,sf,minv(msub(1,mmult(w1f,tf))));
U12=mmult(gamma,sf,minv(msub(1,mmult(w2f,tf))));
U21=mmult(sf,minv(msub(1,mmult(gamma,w1f,tf))));
U22=mmult(sf,minv(msub(1,mmult(gamma,w2f,tf))));

%Figure 6.3
subplot(221);
vplot('liv,lm',L1,U11,U21,1,'w:');
axis([0.1 100 0.6 2.5]);
ylabel('Magnitude');xlabel('Frequency |rad/min|');
text(2,0.95,'L1');text(2,1.06,'U1');text(2,1.18,'U2');
set(gca,'Ytickmode','manual');
set(gca,'Ytick',[1 2]);
subplot(222);
vplot('liv,lm',L2,U12,U22,1,'w:');
axis([0.1 100 0.6 2.5]);
ylabel('Magnitude');xlabel('Frequency |rad/min|');
text(2,1.3,'L1');text(1.5,2.2,'U1');text(20,1.25,'U2');
set(gca,'Ytickmode','manual');
set(gca,'Ytick',[1 2]);

