%Section 12.4.2. Detailed LV-model
clear all;close all;
%Model (12.19)
% Distillation column model with 5 states and disturbances
% See Hovd and Skogestad, Auomatica, p. 989-996, 1992. 

A = [ -5.131e-3 0 0 0 0; 0 -7.366e-2 0 0 0; 0 0 -1.829e-1 0 0;
       0 0 0 -4.620e-1  9.895e-1; 0 0 0 -9.895e-1 -4.620e-1]

B = [-.629 .624; .055 -0.172; 0.030 -0.108; 
      -0.186 -0.139; -1.23 -0.056]


C= [-0.7223 -0.5170 0.3386 -0.1633e-1 0.1121;
    -0.8913 0.4728 0.9876 0.8425 0.2186]

D = [ 0 0; 0 0]


Bd = [-0.062 -0.067; 0.131 0.040; 0.022 -0.106; 
     -0.188 0.027; -0.045 0.014]

G = pck(A,B,C,D);
Gd = pck(A,Bd,C,D);
[Ad,Bd,Cd,Dd]=unpck(Gd);

%-------------------------------------------------------------
%Analysis of model
%-------------------------------------------------------------

szeros(G)

% Steady-state analysis
G0 = -C*inv(A)*B + D
Gd0 = -Cd*inv(Ad)*Bd + Dd
RGA0=vrga(G0)
PRGA0 = mmult(vdiag(vdiag(G0)),minv(G0))
CLDG0 = mmult(PRGA0,Gd0)
GinvGd0 = mmult(inv(G0),Gd0)


w = logspace(-3,1,41);
Gf = frsp(G,w); Gdf=frsp(Gd,w);

%%%%%%%%%%%% MAKE FIGURE 12.16:
rgag=vrga(Gf);
subplot(221)
vplot('liv,lm',vsvd(Gf),1,':');
axis([0.001,10,.1,300]);drawnow
subplot(222)
vplot('liv,lm',rgag,1,':');
axis([0.001,10,.1,300]);




