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
Basics1_Linear.m
Go to the documentation of this file.
1 namespace demos{
2 
3 
4 /* (Autoinserted by mtoc++)
5  * This source code has been filtered by the mtoc++ executable,
6  * which generates code that can be processed by the doxygen documentation tool.
7  *
8  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
9  * Except for the comments, the function bodies of your M-file functions are untouched.
10  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
11  * attached source files that are highly readable by humans.
12  *
13  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
14  * the correct locations in the source code browser.
15  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
16  */
17 
18 function Basics1_Linear() {
19 
20 
21 /* Metadata */
22 dim = 4;
23 s = RandStream(" mt19937ar "," Seed ",0);
24 
25 /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26  *% %%%%%%%%%%%% Simple linear model %%%%%%%%%%%%
27  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28  *% Initialize the base model */
29 m = models.BaseFullModel(" LinearModelDemo ");
30 /* Max simulation time */
31 m.T= 1.5;
32 /* The desired timestepping (output) */
33 m.dt= 0.01;
34 /* The internal maximum timestep for any solver (details later) */
35 m.System.MaxTimestep= m.dt;
36 disp(m);
37 
38 /* % Set the basic components
39  * Only a core linear matrix A and an initial condition are needed here. */
40 m.System.A= dscomponents.LinearCoreFun(s.rand(dim,dim));
41 m.System.x0= dscomponents.ConstInitialValue(10*(s.rand(dim,1)-.5));
42 
43 /* % Run a simple simulation and plot the results */
44 [t,y,ct,x] = m.simulate;
45 fprintf(" Simulation time: %g\n ",ct);
46 /* Plot the system output */
47 m.plot(t,y);
48 /* Plot the state space - here the same, as no specific output conversion is
49  * set */
50 m.plotState(t,x);
51 
52 /* % Modify the inputs and outputs
53  * Now we only want the first DoF as output */
54 m.System.C= dscomponents.LinearOutputConv([1; zeros(dim-1,1)]^t);
55 /* And we also add some system inputs!
56  * This is split into B*u(t), so we need both components. */
57 u1 = @(t)-200*exp(-(t-.5).^2/3);
58 u2 = @(t)200*sin(10*t).*(t>.3);
59 m.System.Inputs[1] = u1;
60 m.System.Inputs[2] = u2;
61 figure;
62 plot(m.Times,u1(m.Times)," r ",m.Times,u2(m.Times)," b ");
63 legend(" u1 "," u2 ");
64 /* Lets map the inputs to the second DoF */
65 m.System.B= dscomponents.LinearInputConv([0; 1; zeros(dim-2,1)]);
66 
67 /* % Run simulation and plot the results
68  * The first argument is a parameter by convention - so leave [] for input
69  * selection. */
70 [t,y,~,x] = m.simulate([],1);
71 m.plot(t,y);
72 m.plotState(t,x);
73 
74 [t,y,~,x] = m.simulate([],2);
75 m.plot(t,y);
76 m.plotState(t,x);
77 
78 /* % Lets use a different solver
79  * Choose explicit Heun's method */
80 m.ODESolver= solvers.Heun;
81 [t,y_heun] = m.simulate([],2);
82 m.plot(t,y_heun);
83 
84 /* Choose the MatLab-builtin ode15i implicit solver */
85 m.ODESolver= solvers.MLode15i;
86 [t,y_impl] = m.simulate([],2);
87 m.plot(t,y_impl);
88 figure;
89 semilogy(t,abs(y_impl-y_heun));
90 
91 /* % Adding a mass matrix E
92  * Choose a positive definite matrix */
93 Mmat = diag(s.randi(20,1,dim)) + s.rand(dim,dim);
94 m.System.M= dscomponents.ConstMassMatrix(Mmat);
95 m.ODESolver= solvers.Heun;
96 [t,y] = m.simulate([],1);
97 m.plot(t,y);
98 
99 m.ODESolver= solvers.MLode15i;
100 [t,y2] = m.simulate([],1);
101 m.plot(t,y2);
102 }
127 };
function Basics1_Linear()
Basics_Linear: Demo file for KerMor linear models and reduction.