Home > classes > @ssm > minreal.m

minreal

PURPOSE ^

minreal gives a minimal realization of a ssm object by deleting state

SYNOPSIS ^

function varargout = minreal(varargin)

DESCRIPTION ^

 minreal gives a minimal realization of a ssm object by deleting state
 variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: minreal gives a minimal realization of a ssm object by
              deleting state variables 
 
 CALL:        Convert a statespace model object to a MATLAB statespace object.
              >> sys = minreal(sys);

            sys - an array of ssm object
 

 VERSION:     $Id: ssm2ss.m,v 1.6 2008/06/08 18:44:07 adrien Exp $

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

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

 HISTORY: 20-08-2008 A Grynagier
             Creation
 TODO : Whole code will be rewritten. It turns out that the numerical
 discrepancies in the matlab minreal function case the whole system to
 become unstable!!!! I have to delete states 'by hand' or leave them as
 they are for now.... 
 I will code a function that will delete unreachable states but leave
 those that are reachable but pz cancelled.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % minreal gives a minimal realization of a ssm object by deleting state
0002 % variables
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: minreal gives a minimal realization of a ssm object by
0006 %              deleting state variables
0007 %
0008 % CALL:        Convert a statespace model object to a MATLAB statespace object.
0009 %              >> sys = minreal(sys);
0010 %
0011 %            sys - an array of ssm object
0012 %
0013 %
0014 % VERSION:     $Id: ssm2ss.m,v 1.6 2008/06/08 18:44:07 adrien Exp $
0015 %
0016 % M-FILE INFO: Get information about this methods by calling
0017 %              >> ssm.getInfo('minreal')
0018 %
0019 %              Get information about a specified set-plist by calling:
0020 %              >> ssm.getInfo('minreal', 'Default')
0021 %
0022 % HISTORY: 20-08-2008 A Grynagier
0023 %             Creation
0024 % TODO : Whole code will be rewritten. It turns out that the numerical
0025 % discrepancies in the matlab minreal function case the whole system to
0026 % become unstable!!!! I have to delete states 'by hand' or leave them as
0027 % they are for now....
0028 % I will code a function that will delete unreachable states but leave
0029 % those that are reachable but pz cancelled.
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 function varargout = minreal(varargin)
0034 
0035 %% starting initial checks
0036 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
0037 
0038 % Check if this is a call for parameters
0039 if utils.helper.isinfocall(varargin{:})
0040   varargout{1} = getInfo(varargin{3});
0041   return
0042 end
0043 
0044 % checking number of inputs work data
0045 if ~nargin==2, error('wrong number of inputs!'), end
0046 
0047 if ~isequal(class(varargin{1}),'ssm'), error(['argument is not a ssm but a ', class(varargin{1})]),end
0048 
0049 sys = varargin{1};
0050 
0051 %% begin function body
0052 for i_sys=1:length(sys)
0053   if ~sys(i_sys).isnumerical
0054     error('system should be numeric')
0055   end
0056   ss = ssm2ss(sys(i_sys), plist);
0057   ss = minreal(ss);
0058   [A,B,C] = ssdata(ss);
0059   sys(i_sys).amats = {A};
0060   sys(i_sys).mmats = {eye(size(A))};
0061   
0062   bmats = cell(1, sys(i_sys).Ninputs);
0063   inputranks = cumsum([1, sys(i_sys).inputsizes]);
0064   for i=sys(i_sys).Ninputs
0065     bmats{i} = B(:, inputranks(i):(inputranks(i+1)-1));
0066   end
0067   
0068   cmats = cell(sys(i_sys).Noutputs,1);
0069   outputranks = cumsum([1, sys(i_sys).outputsizes]);
0070   for i=sys(i_sys).Noutputs
0071     cmats{i} = C(outputranks(i):(outputranks(i+1)-1), :);
0072   end
0073   
0074   sys(i_sys).bmats = bmats;
0075   sys(i_sys).cmats = cmats;
0076   sys(i_sys).amats_handles = cell(1,1);
0077   sys(i_sys).bmats_handles = cell(1,sys(i_sys).Ninputs);
0078   sys(i_sys).cmats_handles = cell(sys(i_sys).Noutputs,1);
0079   sys(i_sys).dmats_handles = {};
0080   sys(i_sys).sssizes =[];
0081   sys(i_sys).ssnames = sys(i_sys).ssnames(1);
0082   sys(i_sys).ssvarnames = {};
0083   
0084   if (sys(i_sys).Nss > 1)
0085     utils.helper.msg(utils.const.msg.MNAME, ['warning in ', mfilename, ' : state space blocks will be fusionned!!!']);
0086   end
0087   sys(i_sys) = validate(sys(i_sys));
0088 end
0089 varargout{1} = sys;
0090 
0091 end
0092 
0093 
0094 function ii = getInfo(varargin)
0095   if nargin == 1 && strcmpi(varargin{1}, 'None')
0096     sets = {};
0097     pls   = [];
0098   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0099     sets{1} = varargin{1};
0100     pls = getDefaultPlist(sets{1});
0101   else
0102     sets = {'Default'};
0103     pls = [];
0104     for kk=1:numel(sets)
0105       pls = [pls getDefaultPlist(sets{kk})];
0106     end
0107   end
0108   % Build info object
0109   ii = minfo(mfilename, 'ssm', '', 'STATESPACE', '$Id: resp.m,v 1.17 2008/07/22 10:22:38 ingo Exp $', sets, pls);
0110 end
0111 
0112 function plo = getDefaultPlist(set)
0113   switch set
0114     case 'Default'
0115       plo = plist();
0116     otherwise
0117       error('### Unknown parameter set [%s].', set);
0118   end
0119 end
0120

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