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
MarkertLaw.m
Go to the documentation of this file.
1 namespace models{
2 namespace muscle{
3 namespace functions{
4 
5 
6 /* (Autoinserted by mtoc++)
7  * This source code has been filtered by the mtoc++ executable,
8  * which generates code that can be processed by the doxygen documentation tool.
9  *
10  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
11  * Except for the comments, the function bodies of your M-file functions are untouched.
12  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
13  * attached source files that are highly readable by humans.
14  *
15  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
16  * the correct locations in the source code browser.
17  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
18  */
19 
30  public: /* ( Constant ) */
31 
32  static const LatestLinearizationLambda = 5;
33 
34 
35  public:
36 
37  b;
38 
39  d;
40 
42 
43  t0 = "[]";
44 
45  ft0 = "[]";
46 
47 
48  public:
49 
51  if nargin < 3
52  max_modulus = [];
53  /* Take data from fit to original function over [1 1.3]
54  * -> general.functions.MarkertLaw.test_FitToOriginal(general.functions.MarkertLawOriginal,[1 1.3]); */
55  if nargin < 2
56  d = 0.1660;
57  if nargin < 1
58  b = 1.3720e8;
59  end
60  end
61  end
62  this.b= b;
63  this.d= d;
64  if ~isempty(max_modulus) /* && d > 1 */
65 
66  [f,df] = this.getFunction;
67  rightval = 2;
68  found = false;
69  while ~found
70  pts = linspace(1,rightval,3);
71  /* Compute maxit to the numer of iterations where the
72  * interval length divided by 2^maxit < eps */
73  maxit = ceil(log((pts(3)-pts(1))/eps)/log(2));
74  it = 0; diff = Inf;
75  while diff > sqrt(eps) && it < maxit;
76  fpts = df(pts)-max_modulus;
77  if fpts(2) < 0
78  pts = [pts(2) (pts(2)+pts(3))/2 pts(3)];
79  else
80  pts = [pts(1) (pts(1)+pts(2))/2 pts(2)];
81  end
82  diff = abs(fpts(2));
83  it = it+1;
84  if pts(2) > this.LatestLinearizationLambda
85  found = true;
86  break;
87  end
88  end
89  if rightval-pts(2) < 1e-10
90  rightval = rightval*2;
91  /* fprintf('Increasing right interval value to %d\n',rightval); */
92  else
93  found = true;
94  end
95  end
96  this.t0= pts(2);
97  fprintf(" Found t0=%5.3g with diff %g to max modulus/derivative of %g after %d iterations (b=%g, d=%g).\n ",...
98  this.t0,diff,max_modulus,it,b,d);
99  this.ft0= f(this.t0);
100  this.max_modulus= max_modulus;
101  end
102  }
103 
104 
105  function [fhandle , dfhandle , fbdhandle , dfbdhandle ] = getFunction() {
106  b1 = this.b;
107  d1 = this.d;
108  tlin = this.t0;
109  if ~isempty(tlin)
110  mm = this.max_modulus;
111  ftlin = this.ft0;
112  /* fhandle = @(t)(t<tlin).*max(0,b1.*(t.^d1-1)) + (t>=tlin).*(ftlin + mm*(t-tlin));
113  *dfhandle = @(t)(t<tlin).*max(0,b1.*((d1-2).*t.^d1+2)) + (t>=tlin)*mm; */
114  fhandle = @(t)(t >= 1 & t<tlin).*(b1./t.^2.*(t.^d1-1).*(t-1).^2)...
115  + (t>=tlin).*(ftlin + mm*(t-tlin));
116  dfhandle = @(t)(t >= 1 & t<tlin).*(b1.*(t-1)./t.^3.*((d1*(t-1)+2).*t.^d1-2)) ...
117  + (t>=tlin)*mm;
118  fbdhandle = @(t,b1,d1)(t >= 1 & t<tlin).*(b1./t.^2.*(t.^d1-1).*(t-1).^2)...
119  + (t>=tlin).*(ftlin + mm*(t-tlin));
120  dfbdhandle = @(t,b1,d1)(t >= 1 & t<tlin).*(b1.*(t-1)./t.^3.*((d1*(t-1)+2).*t.^d1-2)) ...
121  + (t>=tlin)*mm;
122  else
123 /* fhandle = @(t)max(0,b1.*(t.^d1-1));
124  * dfhandle = @(t)max(0,b1.*((d1-2).*t.^d1+2)); */
125  fhandle = @(t)(t>=1).*(b1./t.^2.*(t.^d1-1).*(t-1).^2);
126  dfhandle = @(t)(t>=1).*b1.*(t-1)./t.^3.*((d1*(t-1)+2).*t.^d1-2);
127  fbdhandle = @(t,b1,d1)(t>=1).*(b1./t.^2.*(t.^d1-1).*(t-1).^2);
128  dfbdhandle = @(t,b1,d1)(t>=1).*b1.*(t-1)./t.^3.*((d1*(t-1)+2).*t.^d1-2);
129  end
130  }
131 
132 
133  function str = getConfigStr() {
134  str = sprintf(" b: %g, d: %g, MaxModulus:%g ",this.b,this.d,this.max_modulus);
135  }
136 
137 
138  function plot(range,varargin) {
139  if nargin < 2
140  if ~isempty(this.t0)
141  range = [1 1.2*this.t0];
142  else
143  range = [1 1.2];
144  end
145  end
146  plot@general.functions.AFunGen(this, " R ", range, varargin[:]);
147  if (range(2) > this.t0)
148  ax = get(gcf," Children ");
149  ax = ax(2); /* second one is the left one - hope this is reproducible */
150 
151  hold(ax," on ");
152  plot(ax,this.t0,this.ft0," rx "," MarkerSize ",16);
153  end
154  }
155 
156 
157  public: /* ( Static ) */
158 
159  static function test_Linarization() {
160  C = Utils.createCombinations([1 5],linspace(3,40,5),linspace(100,1e6,5));
161  x = linspace(.3,6,300);
162  pm = PlotManager(false,1,2);
163  pm.LeaveOpen= true;
164  ax = pm.nextPlot(" markertfun_lintest "," Plots for various parameters "," lambda "," value ");
165  axl = pm.nextPlot(" markertfun_lintest_log "," Plots for various parameters "," lambda "," value ");
166  for i = 1:size(C,2)
167  ml = models.muscle.functions.MarkertLaw(C(1,i),C(2,i),C(3,i));
168 /* ml.plot(x); */
169  [f,df] = ml.getFunction;
170  fx = f(x);
171  plot(ax,x,fx," b ");
172  semilogy(axl,x,fx," b ");
173  fprintf(" t0=%g, f(t0)=%g for %s\n ",ml.t0, ml.ft0, ml.getConfigStr);
174 
175  hold(ax," on ");
176  hold(axl," on ");
177 
178  ml = models.muscle.functions.MarkertLaw(C(1,i),C(2,i),[]);
179 /* ml.plot(x); */
180  [f,df] = ml.getFunction;
181  fx = f(x);
182  plot(ax,x,fx," r ");
183  semilogy(axl,x,fx," r ");
184  end
185  pm.done;
186  ylim(ax,[0 1e6]);
187  }
188 
189 
190  static function [res , fit , fitlin ] = test_FitToOriginal(orig,range) {
191  if nargin < 2
192  range = [1 1.2];
193  if nargin < 1
194  orig = models.muscle.functions.MarkertLawOriginal(7990, 16.6);
195  end
196  end
197  ntest = 100;
198  fac = 100;
199  p = Utils.createCombinations(...
200  linspace(orig.b/fac,orig.b*fac*1000,ntest),...
201  linspace(orig.d/fac,orig.d*fac,ntest));
202  l = linspace(range(1),range(2),100);
203  of = orig.getFunction;
204  n = size(p,2);
205  forig = of(l);
206  err = zeros(1,n);
207  pi = ProcessIndicator(" Performing fit for %d cases ",n,false,n);
208  for k=1:n
209  m = models.muscle.functions.MarkertLaw(p(1,k),p(2,k));
210  mf = m.getFunction;
211  ftest = mf(l);
212  err(k) = norm(forig-ftest);
213  pi.step;
214  end
215  pi.stop;
216  [~, idx] = min(err(1,:));
217  fit = models.muscle.functions.MarkertLaw(p(1,idx),p(2,idx));
218  fitlin = models.muscle.functions.MarkertLaw(p(1,idx),p(2,idx),1e5);
219  orig.plot(l);
220  fit.plottofigure(gcf,l," P ",[" r "]);
221  fitlin.plottofigure(gcf,l," P ",[" g "]);
222  res = true;
223  }
224 
225 
226 
227 };
228 }
229 }
230 }
231 
232 
233 
Collection of generally useful functions.
Definition: Utils.m:17
static function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
Definition: Utils.m:114
function plot(range, varargin)
Definition: MarkertLaw.m:138
Returns the modified markert law functions for the OVERALL energy density funcion derivative w...
Definition: MarkertLaw.m:20
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
MarkertLaw(b, d, max_modulus)
Definition: MarkertLaw.m:50
static const LatestLinearizationLambda
Definition: MarkertLaw.m:32
static function [ res , fit , fitlin ] = test_FitToOriginal(orig, range)
Definition: MarkertLaw.m:190
A variable number of input arguments.
static function test_Linarization()
Definition: MarkertLaw.m:159
AFUNGEN Summary of this class goes here Detailed explanation goes here.
Definition: AFunGen.m:19
function [ fhandle , dfhandle , fbdhandle , dfbdhandle ] = getFunction()
Definition: MarkertLaw.m:105
ProcessIndicator: A simple class that indicates process either via waitbar or text output...