KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FuncSum.m
Go to the documentation of this file.
1 namespace general{
2 namespace functions{
3 
4 
5 /* (Autoinserted by mtoc++)
6  * This source code has been filtered by the mtoc++ executable,
7  * which generates code that can be processed by the doxygen documentation tool.
8  *
9  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
10  * Except for the comments, the function bodies of your M-file functions are untouched.
11  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
12  * attached source files that are highly readable by humans.
13  *
14  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
15  * the correct locations in the source code browser.
16  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
17  */
18 
19 class FuncSum
27  private:
28 
29  fungens;
30 
31 
32  public:
33 
35  if length(varargin) < 2
36  error(" Must have at least two summands! ");
37  end
38  this.fungens= varargin;
39  }
40 
41 
42  function [fhandle , dfhandle ] = getFunction() {
43  f = this.fungens;
44  names = cell(1,length(f));
45  for k = 1:length(f)
46  mc = metaclass(f[k]);
47  [~,name] = fileparts(which(mc.Name));
48  names[k] = sprintf(" %s%d ",name,k);
49  eval(sprintf(" %s = f{%d}.getFunction; ",names[k],k));
50  end
51  /* Add (t) argument */
52  names = cellfun(@(s)sprintf(" %s(t) ",s),names," UniformOutput ",false);
53  /* Join with + */
54  sumstr = Utils.implode(names," + ");
55  /* Eval to readable handle */
56  eval(sprintf(" fhandle = @(t)%s; ",sumstr));
57  dfhandle = [];
58  }
59 
60 
61  function str = getConfigStr() {
62  str = this.fungens[1].getConfigStr;
63  for k = 2:length(this.fungens)
64  str = sprintf(" / %s ",this.fungens[k].getConfigStr);
65  end
66  }
67 
68 
69  public: /* ( Static ) */
70 
71  static function res = test_FuncSum() {
72  f1 = general.functions.PiecewiseLinear(-1:.3:1);
73  f1h = f1.getFunction;
74  w = rand(3,1)*5;
75  f2 = general.functions.Sinus(w(1),w(2),w(3));
76  f2h = f2.getFunction;
77  w = rand(3,1)*5;
78  f3 = general.functions.Sinus(w(1),w(2),w(3));
79  f3h = f3.getFunction;
80 
81  fs = general.functions.FuncSum(f1,f2,f3);
82  fsh = fs.getFunction;
83 
84  res = true;
85  for x = -1:.1:1
86  res = res && f1h(x)+f2h(x)+f3h(x) == fsh(x);
87  end
88  fs.plot;
89  }
90 
91 
92 
93 };
94 }
95 }
96 
97 
98 /* /* Speed te*/
99  Speed test
100  * all(1:3) = 0;
101  * for k=1:1000
102  * slen = min(len)*.99 + rand*(max(len)*1.01-min(len)*.99);
103  * t = tic;
104  * %sproc = spline(len,proc,slen);
105  * sproc = pchip(len,proc,slen);
106  * all(1) = all(1) + toc(t);
107  * l = rand*3;
108  * t = tic;
109  * fl(l);
110  * all(2) = all(2) + toc(t);
111  * t = tic;
112  * polyval(pol,slen);
113  * all(3) = all(3) + toc(t);
114  * end
115  * all / 1000
*for k
Definition: FuncSum.m:101
Collection of generally useful functions.
Definition: Utils.m:17
* t
Definition: FuncSum.m:103
* sproc
Definition: FuncSum.m:104
A MatLab cell array or matrix.
A variable number of input arguments.
* l
Definition: FuncSum.m:107
Speed test * all(1:3)
function [ fhandle , dfhandle ] = getFunction()
Definition: FuncSum.m:42
AFUNGEN Summary of this class goes here Detailed explanation goes here.
Definition: AFunGen.m:19
* fl(l)
* polyval(pol, slen)
static function res = test_FuncSum()
Definition: FuncSum.m:71
static function char str = implode(char|rowvec data,char glue,char format)
Implodes the elements of data using glue.
Definition: Utils.m:208
function str = getConfigStr()
Definition: FuncSum.m:61