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