0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % SOP apply a symbolic operation to the expression.
|
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: SOP apply a symbolic operation to the expression.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % CALL: obj = sop(mdl, plist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % obj = mdl.sop(plist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'sop')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % VERSION: $Id: sop.m,v 1.7 2011/04/08 08:56:28 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 function sop(mdls, callerIsMethod, smodel_invars, operation, args, pl, info, varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 if isempty(operation)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 error('### Please give a valid symbolic operator');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % Loop over the input objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 for jj = 1:numel(mdls)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % Message
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 utils.helper.msg(msg.PROC1, 'applying %s to %s ', operation, mdls(jj).name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % Fix syntax (replacing .* with * and so) to allow symbolic evaluation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 mdls(jj).expr.s = utils.prog.convertComString(mdls(jj).expr.s , 'ToSymbolic');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % Go symbolic now
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 d = feval(operation, sym(mdls(jj).expr.s), args{:});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % Go back to string
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 mdls(jj).expr.s = utils.prog.mup2mat(d);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % Replace * like expressions with .* to allow numeric evaluation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 mdls(jj).expr.s = utils.prog.convertComString(mdls(jj).expr.s , 'FromSymbolic');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % In the case of transforms, sets the new x variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 switch lower(operation)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 case {'laplace', 'ilaplace', 'fourier', 'ifourier', 'ztrans', 'iztrans'}
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 if ~isempty(args)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % The return variable is the last argument
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 mdls(jj).xvar = args{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 if ~callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % Set new AO name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 mdls(jj).name = [operation '(' smodel_invars{jj} ')'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 % Add history step
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 mdls(jj).addHistory(info, pl, smodel_invars(jj), mdls(jj).hist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|