%% Reduce Model Order
% Use this script to reduce the order of an LTI model using the Reduce Model Order Live Editor task.
% Load a model.

load build G
size(G)

%
% The LTI model G is a state-space model with 48 states. Some of these states can be discarded while preserving relevant dynamics. Use the Reduce Model Order task to try different reduction methods and different reduced-model orders. The task automatically generates and executes code for the model-reduction parameters you specify. For more information about the task and the available model-reduction methods, see the Reduce Model Order task reference page.
%

% Reduce LTI model order using balanced truncation
 
% Create option set for balred command
Options = balredOptions();
% State elimination method
Options.StateElimMethod = 'Truncate';
% Frequency range for computing state contributions
Options.FreqIntervals = [3.946 22.68];
 
% Compute reduced order approximation on specified frequency range
G_bt = balred(G,8,Options);
 
% Remove temporary variables from Workspace
clear Options

%
% You can now use the reduced model G_red for further analysis or control design. For instance, compare the step responses of G and G_bt. If you create more reduced-order models, examine their responses too.

step(G,G_bt,15)
legend