comparison m-toolbox/classes/@ssm/settlingTime.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SETTLINGTIME retunrns 1% the settling time of the system.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETTLINGTIME retunrns 1% the settling time of the system.
5 % It is a worst scenario assumption were all variable are
6 % used.
7 %
8 % CALL: time = modifyTimeStep(sys,options)
9 %
10 % INPUTS:
11 % sys - (array of) ssm objects
12 % options - A plist or numeric value giving new timestep value (param name 'newtimestep')
13 %
14 % OUTPUTS:
15 % sys - (array of) ssm
16 %
17 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'settlingTime')">Parameters Description</a>
18 %
19 % VERSION: $Id: settlingTime.m,v 1.4 2011/04/08 08:56:22 hewitson Exp $
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23 function varargout = settlingTime(varargin)
24 %% starting initial checks
25
26 % Check if this is a call for parameters
27 if utils.helper.isinfocall(varargin{:})
28 varargout{1} = getInfo(varargin{3});
29 return
30 end
31
32 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
33
34 % Collect input variable names
35 in_names = cell(size(varargin));
36 for ii = 1:nargin,in_names{ii} = inputname(ii);end
37
38 % Collect all SSMs and plists
39 sys = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
40
41 %% begin function body
42 if ~ numel(sys)==1
43 error('settlingTime take only one input ssm object')
44 end
45
46 %% building output depending on options
47 if ~sys.isnumerical
48 error(['error in settlingTime because system "',sys.name, '" should be numerical to find settling time' ]);
49 end
50 % retriveing system infos
51 Ts = sys.timestep;
52 if Ts == 0
53 sys.modifyTimeStep(0.001)
54 Ts = 0.001;
55 end
56 A = double(sys);
57 % initializing calculus
58 tSettling = Ts;
59 k=1;
60 Xini = ones(size(A,2), 1);
61 if numel(Xini)>0
62 % iteration to observe decay
63 while max(abs(Xini)>0.01) && Ts<1e10
64 k = k+1;
65 tSettling = tSettling + Ts;
66 Xini = A*Xini;
67 % multiply timeStep by 2 after 20 iterations
68 if k==20
69 k=1;
70 A = A*A;
71 Ts = 2*Ts;
72 end
73 end
74 else
75 tSettling = 0;
76 end
77 varargout{1} = plist('settling_time', tSettling);
78 end
79
80
81 %--------------------------------------------------------------------------
82 % Get Info Object
83 %--------------------------------------------------------------------------
84 function ii = getInfo(varargin)
85
86 if nargin == 1 && strcmpi(varargin{1}, 'None')
87 sets = {};
88 pl = [];
89 else
90 sets = {'Default'};
91 pl = getDefaultPlist;
92 end
93 % Build info object
94 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.output, '$Id: settlingTime.m,v 1.4 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
95 end
96
97 %--------------------------------------------------------------------------
98 % Get Default Plist
99 %--------------------------------------------------------------------------
100 function pl = getDefaultPlist()
101 pl = plist();
102
103 p = param({'discretize', 'The timestep used for a time-discrete system'}, 0.001 );
104 pl.append(p);
105 end