Home > classes > @ssm > reduce_model.m

reduce_model

PURPOSE ^

REDUCE_MODEL enables to do model simplification

SYNOPSIS ^

function varargout = reduce_model(varargin)

DESCRIPTION ^

 REDUCE_MODEL enables to do model simplification
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


 DESCRIPTION: reduce_model allows to eliminate state space variables.

 CALL:        [ssm] = reduce_model(ssm, options);

 INPUTS :   
             ssm     - a ssm object
             options - an options plist
 
 OPTIONS :
 plist with parameters 'inputs', 'states' and 'outputs' to indicate which
 inputs, states and outputs variables are taken in account. This requires
 proper variable naming. If a variable called appears more that once it
 will be used once only.
 The field may be :
              - a cellstr containing the resp. input/state/output *variable* names
              - a logical indexing the resp. input/state/output
                *variables*. Index is stored in a cell array, each cell 
                correponding to one input/state/output block.
              - a double indexing the resp. input/state/output
                *variables*. Index is stored in a cell array, each cell 
                correponding to one input/state/output block.
              - 'ALL', this string indicates all i/o variables will be
                given
 
 OUTPUTS:
           The output array are of size Nsys*Noptions
 sys_out -  (array of) ssm objects without the specified information

 M-FILE INFO: Get information about this methods by calling
              >> ssm.getInfo('reduce_model')

              Get information about a specified set-plist by calling:
              >> ssm.getInfo('reduce_model', 'Default')

 HISTORY:  05-08-2008 A Grynagier Creation

 TODO :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % REDUCE_MODEL enables to do model simplification
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 %
0005 % DESCRIPTION: reduce_model allows to eliminate state space variables.
0006 %
0007 % CALL:        [ssm] = reduce_model(ssm, options);
0008 %
0009 % INPUTS :
0010 %             ssm     - a ssm object
0011 %             options - an options plist
0012 %
0013 % OPTIONS :
0014 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
0015 % inputs, states and outputs variables are taken in account. This requires
0016 % proper variable naming. If a variable called appears more that once it
0017 % will be used once only.
0018 % The field may be :
0019 %              - a cellstr containing the resp. input/state/output *variable* names
0020 %              - a logical indexing the resp. input/state/output
0021 %                *variables*. Index is stored in a cell array, each cell
0022 %                correponding to one input/state/output block.
0023 %              - a double indexing the resp. input/state/output
0024 %                *variables*. Index is stored in a cell array, each cell
0025 %                correponding to one input/state/output block.
0026 %              - 'ALL', this string indicates all i/o variables will be
0027 %                given
0028 %
0029 % OUTPUTS:
0030 %           The output array are of size Nsys*Noptions
0031 % sys_out -  (array of) ssm objects without the specified information
0032 %
0033 % M-FILE INFO: Get information about this methods by calling
0034 %              >> ssm.getInfo('reduce_model')
0035 %
0036 %              Get information about a specified set-plist by calling:
0037 %              >> ssm.getInfo('reduce_model', 'Default')
0038 %
0039 % HISTORY:  05-08-2008 A Grynagier Creation
0040 %
0041 % TODO :
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 function varargout = reduce_model(varargin)
0045 
0046   import utils.const.*
0047   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0048   %% starting initial checks
0049 
0050   % Check if this is a call for parameters
0051   if utils.helper.isinfocall(varargin{:})
0052     varargout{1} = getInfo(varargin{3});
0053     return
0054   end
0055 
0056   % checking number of inputs work data
0057   if ~nargin==2, error('wrong number of inputs!'), end
0058 
0059   
0060   % Collect input variable names
0061   in_names = cell(size(varargin));
0062   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0063   
0064   % Collect all SSMs and plists
0065   [sys, ssm_invars] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
0066   pl                = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0067 
0068   % Get defaults:
0069   options = combine(pl, getDefaultPlist('Default'));
0070   
0071   Nsys     = numel(sys);
0072   Noptions = numel(options);
0073   if Nsys ~= 1
0074     error('### Please input (only) one SSM model');
0075   end
0076   
0077   % Decide on a deep copy or a modify, depending on the output
0078   sys = copy(sys, nargout);
0079   
0080   %% begin function body
0081 
0082   % Loop over input systems
0083   for i_sys=1:Nsys
0084     for i_options=1:Noptions
0085       options(i_options) = combine(options(i_options),getDefaultPlist('Default'));
0086       inputs  = find(options(i_options), 'inputs');
0087       outputs = find(options(i_options), 'outputs');
0088       states  = find(options(i_options), 'states');
0089 
0090       % Support single string inputs and single number inputs
0091       if ischar(inputs)  || isnumeric(inputs),  inputs  = {inputs};  end
0092       if ischar(outputs) || isnumeric(outputs), outputs = {outputs}; end
0093       if ischar(states)  || isnumeric(states),  states  = {states};  end
0094       
0095       %% converting the lists of the i/o wanted - ss is not modified
0096       %                                                cell_mat   heigths          widths           lines wanted    cols wanted     line names          col names
0097       [As]                           = ssm.cell_select(sys.amats, sys.sssizes,     sys.sssizes,     states,         states,         sys.ssvarnames,     sys.ssvarnames);
0098       [Ms]                           = ssm.cell_select(sys.mmats, sys.sssizes,     sys.sssizes,     states,         states,         sys.ssvarnames,     sys.ssvarnames);
0099       [Bs, sssizes]                  = ssm.cell_select(sys.bmats, sys.sssizes,     sys.inputsizes,  states,         inputs,         sys.ssvarnames,     sys.inputvarnames);
0100       [Cs]                           = ssm.cell_select(sys.cmats, sys.outputsizes, sys.sssizes,     outputs,        states,         sys.outputvarnames, sys.ssvarnames);
0101       [Ds, outputsizes, inputsizes]  = ssm.cell_select(sys.dmats, sys.outputsizes, sys.inputsizes,  outputs,        inputs,         sys.outputvarnames, sys.inputvarnames);
0102 
0103       [inputvarnames2]   =    ssm.cell_select(sys.inputvarnames,  1,               sys.inputsizes,  {true},         inputs,         {' '},              sys.inputvarnames);
0104       [ssvarnames2]      =    ssm.cell_select(sys.ssvarnames,     1,               sys.sssizes,     {true},         states,         {' '},              sys.ssvarnames);
0105       [outputvarnames2]  =    ssm.cell_select(sys.outputvarnames, 1,               sys.outputsizes, {true},         outputs,        {' '},              sys.outputvarnames);
0106 
0107       sys(i_sys, i_options).amats = As;
0108       sys(i_sys, i_options).mmats = Ms;
0109       sys(i_sys, i_options).bmats = Bs;
0110       sys(i_sys, i_options).cmats = Cs;
0111       sys(i_sys, i_options).dmats = Ds;
0112       sys(i_sys, i_options).inputvarnames  = inputvarnames2;
0113       sys(i_sys, i_options).ssvarnames     = ssvarnames2;
0114       sys(i_sys, i_options).outputvarnames = outputvarnames2;
0115       sys(i_sys, i_options).inputsizes  = inputsizes;
0116       sys(i_sys, i_options).sssizes     = sssizes;
0117       sys(i_sys, i_options).outputsizes = outputsizes;
0118       
0119       sys(i_sys, i_options).name  = [sys(i_sys, i_options).name, ' reduced'];
0120       sys(i_sys, i_options).description = [sys(i_sys, i_options).description, ' reduced'];
0121       sys(i_sys, i_options).addHistory(ssm.getInfo(mfilename), options(i_options) , {''}, sys(i_sys, i_options).hist );
0122     end
0123   end
0124   sys.validate;
0125   if nargout > 0
0126     varargout{1} = sys;
0127   end
0128 end
0129 
0130 %--------------------------------------------------------------------------
0131 % Get Info Object
0132 %--------------------------------------------------------------------------
0133 function ii = getInfo(varargin)
0134   if nargin == 1 && strcmpi(varargin{1}, 'None')
0135     sets = {};
0136     pls   = [];
0137   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0138     sets{1} = varargin{1};
0139     pls = getDefaultPlist(sets{1});
0140   else
0141     sets = {'Default'};
0142     pls = [];
0143     for kk=1:numel(sets)
0144       pls = [pls getDefaultPlist(sets{kk})];
0145     end
0146   end
0147   % Build info object
0148   ii = minfo(mfilename, 'ssm', '', utils.const.categories.statespace, '$Id: resp.m,v 1.17 2008/07/22 10:22:38 ingo Exp $', sets, pls);
0149 end
0150 
0151 %--------------------------------------------------------------------------
0152 % Get Default Plist
0153 %--------------------------------------------------------------------------
0154 function plo = getDefaultPlist(set)
0155   switch set
0156     case 'Default'
0157       plo = plist('inputs','ALL','outputs','ALL', 'states', 'ALL');
0158     otherwise
0159       error('### Unknown parameter set [%s].', set);
0160   end
0161 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003