%% Reduce Model Order
% Given a continuous or discrete, stable or unstable system, G, create a set of reduced-order models based on your selections.

rng(1234,'twister'); % For reproducibility
G = rss(30,5,4);

%
% If you call reduce without specifying an order for the reduced model, the software displays a Hankel singular-value plot and prompts you to select an order.
% If you specify a reduced-model order, reduce defaults to the balancmr algorithm for model reduction.

[g1,redinfo1] = reduce(G,20);

%
% Specify other algorithms using the Algorithm argument. Use the ErrorType argument to specify whether the algorithm uses multiplicative or additive error, and the maximum permissible error in the reduced model.

[g2,redinfo2] = reduce(G,[10:2:18],'Algorithm','schur'); 
[g3,redinfo3] = reduce(G,'ErrorType','mult','MaxError',[0.01 0.05]);
[g4,redinfo4] = reduce(G,'ErrorType','add','Algorithm','hankel','MaxError',[0.01]);
for i = 1:4
    figure(i); eval(['sigma(G,g' num2str(i) ');']);
end

% Copyright 2012 The MathWorks, Inc.