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
LinearSplitOfOne.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
18  :public handle {
37  public:
38 
39  char VarName = "x";
70  public:
71 
72 
73  LinearSplitOfOne(char varname,integer splits,double len) {
74  if nargin > 0
75  this.VarName= varname;
76  if nargin > 1
77  this.Splits= splits;
78  if nargin > 2
79  this.IntervalLength= len;
80  end
81  end
82  end
83  }
94  function str = getFunStr(idx) {
95  if idx > this.Splits || idx < 0
96  error(" Max %d functions (starting at 0) for %d splits ",this.Splits+1,this.Splits);
97  end
98  ilen = this.IntervalLength / this.Splits;
99  if idx == 0
100  str = sprintf(" (1-@@varname@@/%g).*(@@varname@@<%g) ",ilen,ilen);
101  elseif idx == this.Splits
102  str = sprintf(" ((@@varname@@-%g)/%g).*(@@varname@@>=%g) ",(idx-1)*ilen,ilen,(idx-1)*ilen);
103  else
104  /* zero to one */
105  zto = sprintf(" (@@varname@@>=%g).*(@@varname@@<%g).*((@@varname@@-%g)/%g) ",...
106  (idx-1)*ilen,idx*ilen,(idx-1)*ilen,ilen);
107  /* one to zero */
108  otz = sprintf(" (@@varname@@>=%g).*(@@varname@@<%g).*(1-(@@varname@@-%g)/%g) ",...
109  idx*ilen,(idx+1)*ilen,idx*ilen,ilen);
110  str = [zto " + " otz];
111  end
112  str = strrep(str," @@varname@@ ",this.VarName);
113  }
125  function cellfuns = getAllFunctions() {
126  funs = cell(this.Splits+1,1);
127  for idx = 1:this.Splits+1
128  funs[idx] = this.getFunStr(idx-1);
129  end
130  }
139  function handle = getAllFunctionsParsed() {
140  funs = this.getAllFunctions;
141  str = [" @( " this.VarName " )[ "];
142  for idx = 1:this.Splits+1
143  str = [str funs[idx] " ; "];/* #ok */
144 
145  end
146  str = [str " ]; "];
147  handle = eval(str);
148  }
159 #if 0 //mtoc++: 'set.Splits'
160 function Splits(value) {
161  if value < 1
162  error(" Minimum of one split necessary. ");
163  end
164  this.Splits= value;
165  }
166 
167 #endif
168 
169 
170  public: /* ( Static ) */
171 
172  static function res = test_LinearSplitOfOne() {
173  num = 20;
174  s = randi(50,1,num);
175  l = rand(1,num);
176  res = true;
177  for k=1:num
178  lso = LinearSplitOfOne(" x ",s(k),l(k));
179  f = lso.getAllFunctionsParsed;
180 
181  pos = linspace(0,l(k),200);
182  for i=1:length(pos)
183  if i < 200
184  res = res && sum(f(pos(i))) == 1;
185  else
186  fprintf(" Splits: %d, len: %g, diff at end: %g\n ",s(k),l(k),sum(f(pos(i)))-1);
187  end
188  end
189  end
190  }
191 
192 
198 };
199 
LinearSplitOfOne: Computes a sequence of hat functions at equidistant nodes from [0,len] to enable an efficient, easy way of division of unity.
integer Splits
The number of splits to do. Results in +1 functions, indexed starting at 0.
function cell funs = getAllFunctions()
Returns all functions in a cell array.
A MatLab cell array or matrix.
A double value.
LinearSplitOfOne(char varname,integer splits,double len)
Creates a new instance.
An integer value.
Matlab's base handle class (documentation generation substitute)
static function res = test_LinearSplitOfOne()
function handle = getAllFunctionsParsed()
Returns a function handle for a vector function, where each component idx evaluates the (idx-1)-th fu...
function str = getFunStr(idx)
Returns the idx-th function string.
char VarName
The variable name in the function strings.
double IntervalLength
The length of the interval over which to split unity.
A MatLab character array.