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
PiecewiseLinear.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 
27  protected:
28 
29  pts;
30 
32 
33 
34  public:
35 
37  if nargin < 2
38  if nargin < 1
39  x = 0:2;
40  y = [0 1 0];
41  else
42  y = x;
43  x = 1:size(x,2);
44  end
45  end
46  if length(x) ~= length(unique(x))
47  error(" Have to provide disjoint x locations ");
48  end
49  [x, idx] = sort(x," ascend ");
50  y = y(idx);
51  this.pts= x;
52  this.vals= y;
53  }
54 
55 
56  function [fhandle , dfhandle ] = getFunction() {
57  [x,y] = this.transform(this.pts, this.vals);
58  xy = [x;y];
59  nf = size(xy,2)-1;
60  funs = cell(1,nf);
61  dfuns = cell(1,nf);
62  for k=1:nf
63  xy1 = xy(:,k);
64  xy2 = xy(:,k+1);
65  cond = sprintf(" (t>=%g & t <%g) ",xy1(1),xy2(1));
66  a = (xy2(2)-xy1(2))/(xy2(1)-xy1(1));
67  b = xy1(2)-a*xy1(1);
68  fun = sprintf(" (%g*t+%g) ",a,b);
69  funs[k] = [cond " .* " fun];
70  dfuns[k] = [cond " .* " sprintf(" %g ",a)];
71  end
72  funstr = sprintf(" @(t)%s ",Utils.implode(funs," + "));
73  dfunstr = sprintf(" @(t)%s ",Utils.implode(dfuns," + "));
74  fhandle = eval(funstr);
75  dfhandle = eval(dfunstr);
76  }
77 
78 
79  function str = getConfigStr() {
80  str = sprintf(" Points: %d ",size(this.pts,2));
81  }
82 
83 
84  function pm = plot(range) {
85  if nargin < 2
86  x = this.transform(this.pts,this.vals);
87  range = [min(x) max(x)];
88  end
89  pm = plot@general.functions.AFunGen(this, " R ", range);
90  }
91 
92 
93 
94  protected:
95 
96  function [colvec<double>x , matrix<double>y ] = transform(colvec<double> x,matrix<double> y) {
97  }
111  public: /* ( Static ) */
112 
113  static function test_PiecewiseLinear() {
114  p = general.functions.PiecewiseLinear;
115  p.plot;
116  p = general.functions.PiecewiseLinear(rand(1,7));
117  p.plot;
118  p = general.functions.PiecewiseLinear(rand(1,7),rand(1,7));
119  p.plot;
120  }
121 
122 
123 
124 };
125 }
126 }
127 
Collection of generally useful functions.
Definition: Utils.m:17
function [ fhandle , dfhandle ] = getFunction()
A MatLab cell array or matrix.
sort
ort the handle objects in any array in ascending or descending order.
AFUNGEN Summary of this class goes here Detailed explanation goes here.
Definition: AFunGen.m:19
function [ colvec< double > x , matrix< double > y ] = transform(colvec< double > x,matrix< double > y)
gives the chance for subclasses to manipulate the x,y data before the piecewise nonlinear function is...
PiecewiseLinear(colvec< double > x,matrix< double > y)
static function char str = implode(char|rowvec data,char glue,char format)
Implodes the elements of data using glue.
Definition: Utils.m:208
static function test_PiecewiseLinear()