% Table 11.3. 
% MATLAB commands for model reduction of unstable system (CORRECTED)
% Uses the Mu-toolbox 

% Alt. 1
[syss,sysu]=sdecomp(sys);        % decompose into stable and unstable part. 
[sysb,hsig] = sysbal(syss); hsig % balanced realization of stable part

sys1=sresid(sysb,ks);            % balanced residualization 
sys1=hankmr(sysb,hsig,ks,'d');   % or: Hankel norm approx. of stable part.

syssbr=madd(sys1,sysu);          % realize reduced-order system. 

%Alt. 2
[nlcf,hsig,nrcf]=sncfbal(sys);   % balanced realization of coprime factors.
nrcfr=sresid(nrcf,k);            % residualization of coprime factors.
syscbr=cf2sys(nrcfr);            % realize reduced-order system. 

% Alt. 3. Should be similar to Alt.1, but with Robust control toolbox
[a,b,c,d]=unpck(sys);
[ar,br,cr,dr]=ohklmr(a,b,c,d,1,k);
sysbr3 = sysbal(pck(ar,br,cr,dr));


