clc
% MUSYNEX is a simple demo routine illustrating the
% D-F iteration of mu-synthesis.  See also MUDEMO.

echo on

% Plant Data:

a=2;             b1=[.1 -1];          b2=-1;
c1=[1 .01]';    d11=[.1 .2;.01 .01]; d12=[1 0]';
c2=1;           d21=[0  1];          d22=3;
tss_=mksys(a,b1,b2,c1,c2,d11,d12,d21,d22,'tss');
w=logspace(-2,1);


% H-infinity 

[gam0,ss_cp0,ss_cl0]=hinfopt(tss_);
[mu0,logd0]=ssv(ss_cl0,w);

% Mu Synthesis -- Iteration No. 1 (CONSTANT D(s)):

[ss_d1,logd1]=fitd(logd0,w);  
[gam1,ss_cp1,ss_cl1]=hinfopt(augd(tss_,ss_d1));
[mu1,deltalogd]=ssv(ss_cl1,w);



% Mu Synthesis -- Iteration No. 2 (FIRST ORDER D(s)):

[ss_d2,logd2]=fitd(logd1+deltalogd,w,1);
[gam2,ss_cp2,ss_cl2]=hinfopt(augd(tss_,ss_d2));

% Display Optimal hinf cost closed loop and SSV plot

clg
loglog(w,max(sigma(ss_cl2,1,w))/gam2,w,ssv(ss_cl2,w)/gam2);
echo off
pause