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
ParamSweep.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 
17 function [pm , Y , E ] = ParamSweep(rmodel,mu,inputidx,param,paramvals,pm) {
18 
19 
20 /* Validity checks */
21 if ischar(param)
22  pidx = rmodel.getParamIndexFromName(param);
23  pname = param;
24 elseif isposintscalar(param)
25  pidx = param;
26  pname = rmodel.System.Params(pidx).Name;
27 else
28  error(" param must be either a char array (parameter name) or positive parameter index ");
29 end
30 npar = length(paramvals);
31 if npar == 0
32  error(" Parameter values to sweep must be given. ");
33 end
34 if nargin < 6
35  pm = PlotManager;
36 end
37 
38 haveerrest = ~isempty(rmodel.ErrorEstimator) && rmodel.ErrorEstimator.Enabled;
39 
40 /* Iterate over parameter values */
41 Y = zeros(npar,length(rmodel.Times));
42 E = [];
43 if haveerrest
44  E = Y;
45 end
46 pi = ProcessIndicator(" Starting parameter sweep with %d parameter sets for %s... ",npar,false,npar,pname);
47 for idx = 1:npar
48  mu(pidx) = paramvals(idx);
49  [t, y] = rmodel.simulate(mu, inputidx);
50  if size(y,1) > 1
51  y = Norm.L2(y);
52  end
53  Y(idx,:) = y;
54 
55  if haveerrest
56  E(idx,:) = rmodel.ErrorEstimator.OutputError;/* #ok */
57 
58  end
59  pi.step;
60 end
61 pi.stop;
62 
63 /* % Prepare plot */
64 
65 [T,MU] = meshgrid(t,paramvals);
66 ustr = ;
67 if ~isempty(inputidx)
68  ustr = sprintf(" , u_%d ",inputidx);
69 end
70 tit = sprintf(" Outputs for parameter sweep of '%s' (idx:%d) from %1.3f to %1.3f, base \\mu = [%s]%s ",...
71  pname,param,paramvals(1),paramvals(end),num2str(mu^t),ustr);
72 h = pm.nextPlot(" param_sweep ",tit," t ",sprintf(" Parameter %d: %s ",param,pname));
73 /* % Upper bound */
74 if haveerrest
75  obj = surf(h,T,MU,Y+E," EdgeColor "," none "," FaceColor "," red ");
76  alpha(obj,.3);
77 /* mesh(T,MU,Y+E,'EdgeColor','none','FaceColor','red'); */
78  hold on;
79 end
80 
81 /* % y plot */
82 surf(h,T,MU,Y," EdgeColor "," none ");
83 colormap jet;
84 
85 /* % Lower bound */
86 if haveerrest
87  obj = surf(h,T,MU,Y-E," EdgeColor "," none "," FaceColor "," red ");
88  alpha(obj,.3);
89 /* mesh(T,MU,Y-E,'EdgeColor','none','FaceColor','red'); */
90  hold off;
91 end
92 if nargout < 1
93  pm.done;
94 end
95 }
function [ pm , Y , E ] = ParamSweep(rmodel, mu, inputidx, param, paramvals, pm)
ParamSweep: Plots the output with error bounds for a range of one specified parameter.
Definition: ParamSweep.m:17
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
#define Y(i, j)
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
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...