% Example 7.3
% Multiplicative weight for parametric uncertainty (Figure 7.6)
close all;clear all;
w = logspace(-2,2,201);
% Multiplicative uncertainty weight w_I
T = 4;
wi = nd2sys([T 0.2],[T/2.5 1]);
wif=frsp(wi,w);
clf;vplot('liv,lm',wif,1,':');
axis([0.01 10, 0.1, 3]);
xlabel('Frequency');ylabel('Magnitude');
hold on;
disp('This is the first weight we tried.');
drawnow;
% We will find that this weight does NOT include all of the eight plants
% considered (the worst case is for case 5 (k_max, \tau_min and \theta_min)

% Nominal model with Delay-free
k0=2.5; tau0=2.5;
g0 = nd2sys(k0, [tau0 1]); gf0=frsp(g0,w);
G = gf0; 

pars = [2 2.5 3];
for i1=1:3
  theta = sel(pars,1,i1);
  delf = delay(theta,w);
  for i2=1:3
    k = sel(pars,1,i2);
    for i3=1:3
      tau = sel(pars,1,i3);
      g = nd2sys(k, [tau 1]); gf=frsp(g,w);
      Gp = mmult(gf,delf);
      lI = mmult(minv(G),msub(Gp,G));
%      v = [k tau theta pkvnorm(xtract(lI,0.1)) pkvnorm(xtract(lI,0.3)) ...
%	      pkvnorm(xtract(lI,1)) pkvnorm(lI)]
      vplot('liv,lm',lI,':');
      disp(sprintf('This is plant with theta=%4.1f, k=%4.1f.',theta,k));
      drawnow;
    end
  end
end

th = 3/3; z1=0.8; z2=0.7;
corr = nd2sys([th*th 2*z1*th 1],[th*th 2*z2*th 1]);
corrf= frsp(corr,w);
wicorrf=mmult(wif,corrf);
disp('Now we will see the modified weight.');
drawnow;
vplot('liv,lm',wicorrf,'--');  %Figure 7.6


