%Example 8.9
% RS for diagonal input uncertainty
clear all;close all;
tau = 75; eps = 1e-9;
G0=[-87.8 1.4;-108.2 -1.4];
dyn=nd2sys(1,[tau 1]); Dyn=daug(dyn,dyn);
G=mmult(Dyn,G0);

kdyn=nd2sys([tau 1],[1 eps]);Kdyn=daug(kdyn,kdyn);
K0=daug(0.0015,0.075);
K=mmult(Kdyn,K0);

wI = nd2sys( [5 1], [0.5 1], 0.2 );

w = logspace( -3, 2, 101 );
wIjw = frsp( wI, w );
wIinvjw = vinv( wIjw );

LI = mmult( K, G );
SI = minv(madd(eye(2), LI));
TI = mmult( SI, LI );

TIjw = frsp( TI, w );
Sjw  = vsvd( TIjw );

[bnds, dvec, sens, pvec] = mu( TIjw  );

vplot( 'liv,lm', wIinvjw, '-.', sel(Sjw,1,1), '-', sel(bnds,1,1), '-'   );
text( 1, 12, 'sv' ); text(0.002, 8, '1/WI' ); text( 1, 0.3, 'mu' );
xlabel('Frequency');ylabel('Magnitude');

