0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % LAPLACE implements continuous s-domain Laplace transform for smodel objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: LAPLACE implements continuous s-domain Laplace transform for smodel objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % CALL: obj = laplace(mdl, ret_var)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % obj = mdl.laplace(ret_var)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % obj = mdl.laplace(in_var, ret_var) [Please note the order!]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % obj = mdl.laplace(plist('ret_var', ret_var, 'in_var', in_var))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % obj = mdl.laplace(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % INPUTS: mdl - input smodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % ret_var - a string with a variable name to transform into
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % in_var - a string with a variable name to transform with respect to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % pl - input parameter list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % OUTPUTS: obj - output smodel(s)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'laplace')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % VERSION: $Id: laplace.m,v 1.11 2011/04/08 08:56:30 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 function varargout = laplace(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % Settings
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 operatorName = 'laplace';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % Check if the method was called by another method
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 callerIsMethod = utils.helper.callerIsMethod;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % Collect all smodels and plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 [as, smodel_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % Decide on a deep copy or a modify
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 mdls = copy(as, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % Combine input plists and default PLIST
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 pl = parse(pl, getDefaultPlist());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % Select the variable to transform with respect to:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 [in_var, ret_var, pl] = utils.helper.process_smodel_transf_options(pl, rest);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 % Check the independent variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 if isempty(in_var)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 in_var = as.xvar;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 if isempty(in_var)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 error(['### Please specify the independent variable to transform with respect to, ' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 'or set the xvar properties of the model(s)!']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % If the method was called by another method, we do not need to set history.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 % As such, the info object can be empty
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 if callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 infoObj = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 infoObj = getInfo('None');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % Apply the method to all models
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 mdls.sop(callerIsMethod, smodel_invars, operatorName, {in_var, ret_var}, pl, infoObj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % Set units
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 if strcmp(in_var, as.xvar)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 setYunits(mdls, mdls.yunits .* mdls.xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 setXunits(mdls, 1 ./ mdls.xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 % Set output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 varargout{1} = mdls;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 pls = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 pls = getDefaultPlist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.op, '$Id: laplace.m,v 1.11 2011/04/08 08:56:30 hewitson Exp $', sets, pls);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 ii.setArgsmin(1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 function plout = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 persistent pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 if ~exist('pl', 'var') || isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 pl = buildplist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 plout = pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 function pl = buildplist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 pl = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 % Ret_Var
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 p = param({'ret_var', 'Return variable, to transform into.'}, paramValue.STRING_VALUE('s'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 % In_Var
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 p = param({'in_var', ['Independent variable, to transform with respect to.<br>' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 'If left empty, the x variable of the model(s) will be used']}, paramValue.STRING_VALUE(''));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 end
|