%% Order Reduction by Matched-DC-Gain and Direct-Deletion Methods
% Consider the following continuous fourth-order model.
% h(s) = \frac{{{s^3} + 11{s^2} + 36s + 26}}{{{s^4} + 14.6{s^3} +
% 74.96{s^2} + 153.7s + 99.65}}.
% To reduce its order, first compute a balanced state-space realization with balreal.

h = tf([1 11 36 26],[1 14.6 74.96 153.7 99.65]);
[hb,g] = balreal(h);

%
% Examine the gramians.

g'

%
% The last three diagonal entries of the balanced gramians are relatively small. Eliminate these three least-contributing states with modred, using both matched-DC-gain and direct-deletion methods.

hmdc = modred(hb,2:4,'MatchDC');
hdel = modred(hb,2:4,'Truncate');

%
% Both hmdc and hdel are first-order models. Compare their Bode responses against that of the original model.

bodeplot(h,'-',hmdc,'x',hdel,'*')

%
% The reduced-order model hdel is clearly a better frequency-domain approximation of h. Now compare the step responses.

stepplot(h,'-',hmdc,'-.',hdel,'--')

% While hdel accurately reflects the transient behavior, only hmdc gives the true steady-state response.
% Copyright 2015 The MathWorks, Inc.