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')

              Get information about a specified set-plist by calling:
              >> ssm.getInfo('reduce', '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')
0035 %
0036 %              Get information about a specified set-plist by calling:
0037 %              >> ssm.getInfo('reduce', 'Default')
0038 %
0039 % HISTORY:  05-08-2008 A Grynagier Creation
0040 %
0041 % TODO :
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 function varargout = reduce_model(varargin)
0045 
0046   %% starting initial checks
0047   utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
0048 
0049   % Check if this is a call for parameters
0050   if utils.helper.isinfocall(varargin{:})
0051     varargout{1} = getInfo(varargin{3});
0052     return
0053   end
0054 
0055   % checking number of inputs work data
0056   if ~nargin==2, error('wrong number of inputs!'), end
0057 
0058   if ~isequal(class(varargin{1}),'ssm'), error(['argument is not a ssm but a ', class(varargin{1})]),end
0059   if ~isequal(class(varargin{2}),'plist'), error(['argument is not a plist but a ', class(varargin{2})]),end
0060 
0061   sys = varargin{1};
0062   options = varargin{2};
0063   Nsys     = length(sys);
0064   Noptions = length(options);
0065   %% begin function body
0066   
0067   inputs  = find(options, 'inputs');
0068   outputs = find(options, 'outputs');
0069   states  = find(options, 'states');
0070 
0071   %% building output depending on options
0072   if Noptions==1
0073     sys_out(:,1) = reshape(sys,Nsys,1);
0074   else
0075     for j=1:Noptions
0076       sys_out(:,j)=copy(reshape(sys,Nsys,1),true);
0077     end
0078   end
0079   for i_sys=1:Nsys
0080     for i_options=1:Noptions
0081 
0082     
0083       %% converting the lists of the i/o wanted - ss is not modified
0084       %                                                cell_mat   heigths          widths           lines wanted    cols wanted     line names          col names
0085       [As]                           = ssm.cell_select(sys.amats, sys.sssizes,     sys.sssizes,     states,         states,         sys.ssvarnames,     sys.ssvarnames);
0086       [Ms]                           = ssm.cell_select(sys.mmats, sys.sssizes,     sys.sssizes,     states,         states,         sys.ssvarnames,     sys.ssvarnames);
0087       [Bs, sssizes]                  = ssm.cell_select(sys.bmats, sys.sssizes,     sys.inputsizes,  states,         inputs,         sys.ssvarnames,     sys.inputvarnames);
0088       [Cs]                           = ssm.cell_select(sys.cmats, sys.outputsizes, sys.sssizes,     outputs,        states,         sys.outputvarnames, sys.ssvarnames);
0089       [Ds, outputsizes, inputsizes]  = ssm.cell_select(sys.dmats, sys.outputsizes, sys.inputsizes,  outputs,        inputs,         sys.outputvarnames, sys.inputvarnames);
0090 
0091       [ssini]            =    ssm.cell_select(sys.ssini,          sys.sssizes,     1,               states,         {true},         sys.ssvarnames,     {' '});
0092       [inputvarnames2]   =    ssm.cell_select(sys.inputvarnames,  1,               sys.inputsizes,  {true},         inputs,         {' '},              sys.inputvarnames);
0093       [ssvarnames2]      =    ssm.cell_select(sys.ssvarnames,     1,               sys.sssizes,     {true},         states,         {' '},              sys.ssvarnames);
0094       [outputvarnames2]  =    ssm.cell_select(sys.outputvarnames, 1,               sys.outputsizes, {true},         outputs,        {' '},              sys.outputvarnames);
0095 
0096       sys_out(i_sys, i_options).amats = As;
0097       sys_out(i_sys, i_options).mmats = Ms;
0098       sys_out(i_sys, i_options).bmats = Bs;
0099       sys_out(i_sys, i_options).cmats = Cs;
0100       sys_out(i_sys, i_options).dmats = Ds;
0101       sys_out(i_sys, i_options).inputvarnames  = inputvarnames2;
0102       sys_out(i_sys, i_options).ssvarnames     = ssvarnames2;
0103       sys_out(i_sys, i_options).outputvarnames = outputvarnames2;
0104       sys_out(i_sys, i_options).inputsizes  = inputsizes;
0105       sys_out(i_sys, i_options).sssizes     = sssizes;
0106       sys_out(i_sys, i_options).outputsizes = outputsizes;
0107       sys_out(i_sys, i_options).ssini = ssini;
0108       
0109       sys_out(i_sys, i_options).name  = [sys_out(i_sys, i_options).name, ' reduced'];
0110       sys_out(i_sys, i_options).description = [sys_out(i_sys, i_options).description, ' reduced'];
0111       sys_out(i_sys, i_options).addHistory(ssm.getInfo(mfilename), options(i_options) , {''}, sys_out(i_sys, i_options).hist );
0112     end
0113   end
0114   sys_out = validate(sys_out);
0115   varargout = {sys_out};
0116 end
0117 
0118 function ii = getInfo(varargin)
0119   if nargin == 1 && strcmpi(varargin{1}, 'None')
0120     sets = {};
0121     pls   = [];
0122   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0123     sets{1} = varargin{1};
0124     pls = getDefaultPlist(sets{1});
0125   else
0126     sets = {'Default'};
0127     pls = [];
0128     for kk=1:numel(sets)
0129       pls = [pls getDefaultPlist(sets{kk})];
0130     end
0131   end
0132   % Build info object
0133   ii = minfo(mfilename, 'ssm', '', 'STATESPACE', '$Id: resp.m,v 1.17 2008/07/22 10:22:38 ingo Exp $', sets, pls);
0134 end
0135 
0136 function plo = getDefaultPlist(set)
0137   switch set
0138     case 'Default'
0139       plo = plist('inputs','ALL','outputs','ALL', 'states', 'ALL');
0140     otherwise
0141       error('### Unknown parameter set [%s].', set);
0142   end
0143 end

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003