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
InitialConditions.m
Go to the documentation of this file.
1 namespace models{
2 namespace motorunit{
3 namespace experiments{
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 
20 function InitialConditions() {
21 
22 
23 
24 /* Create with no dynamic initial conditions as this script is intended to
25  * compute them :-) */
26 file = fullfile(fileparts(mfilename(" fullpath "))," ic_singletwitch.mat ");
27 filex0 = fullfile(fileparts(mfilename(" fullpath "))," .. "," x0coeff ");
28 if exist(file," file ") == 2
29  load(file);
30 else
31  m = models.motorunit.Shorten(false,true);
32  m.UseNoise= false;
33  s = sampling.ManualSampler;
34  p = linspace(0,1,200);
35  p = [p; ones(size(p))*1];
36  s.Samples= p;
37 
38  m.off1_createParamSamples;
39  m.T= 5000;
40  m.dt= .1;
41 
42  n = size(p,2);
43  maxvals = zeros(1,n);
44  maxidx = [];
45  endvals = zeros(m.System.f.xDim,n);
46  ctimes = zeros(1,n);
47  pi = ProcessIndicator(" Running %d simulations with one twitch ",n/(max(1,matlabpool(" size "))),false,n);
48  /* for k=1:n */
49  parfor k=1:n
50  [t, y, ctimes(k), x] = m.simulate(p(:,k),1);/* #ok */
51 
52  endvals(:,k) = x(:,end);
53  pi.step;/* #ok */
54 
55  end
56  /* Collect all trajectories into the local/main model */
57  m.Data.TrajectoryData.consolidate(m);
58  pi.stop;
59  m.save;
60  save(file, " m ", " endvals ", " p ", " ctimes ");
61 end
62 
63 /* % Fit every dimension by polynomial */
64 deg = 8;
65 dim = size(endvals,1);
66 coeff = zeros(dim,deg+1);
67 err = zeros(dim);
68 a = dscomponents.AffineInitialValue;
69 pi = ProcessIndicator(" Fitting polynomials ",dim);
70 for k=1:dim
71  coeff(k,:) = polyfit(p(1,:),endvals(k,:),deg);
72  err(k) = Norm.Linf((endvals(k,:) - polyval(coeff(k,:),p(1,:)))^t);
73  a.addMatrix(sprintf(" polyval([%s],mu(1)) ",sprintf(" %g ",coeff(k,:))),full(sparse(k,1,1,dim,1)));
74  pi.step;
75 end
76 pi.stop;
77 
78 /* % Error checks */
79 endvals_afflin = zeros(size(endvals));
80 for k=1:n
81  endvals_afflin(:,k) = a.evaluate(p(1,k));
82 end
83 semilogy(p(1,:),Norm.L2(endvals_afflin-endvals)./Norm.L2(endvals));
84 title(sprintf(" Relative errors of initial values for %d increasing mu_1 ",n));
85 
86 save(file, " a ", " endvals_afflin ", " err ", " coeff ", " -APPEND ");
87 save(filex0, " coeff ");
88 }
118 };
119 };
120 };
* polyval(pol, slen)
static function rowvec< double > n = Linf(matrix< double > x)
Returns the discrete norm for each column vector in x.
Definition: Norm.m:73
function InitialConditions()
% Old version: This script runs the motorunit.Model instance without input for 10 seconds...
static function rowvec< double > n = L2(matrix< double > x)
Returns the discrete norm for each column vector in x.
Definition: Norm.m:39
Norm: Static class for commonly used norms on sets of vectors.
Definition: Norm.m:17
ProcessIndicator: A simple class that indicates process either via waitbar or text output...