26 s = RandStream(
" mt19937ar ",
" Seed ",0);
32 m = models.BaseFullModel(
" LinearModelWithParamsDemo ");
35 m.System.MaxTimestep= m.dt;
37 m.ODESolver= solvers.ExplEuler;
41 m.System.addParam(
" P1 (Diffswitch) ",0,
" Range ",[0 1]);
42 m.System.addParam(
" P2 (Exp) ",1,
" Range ",[0 2]);
43 m.System.addParam(
" P3 (SomeOtherName) ",0,
" Range ",[-1 1]);
49 funs = [
" t*mu(1) ",
" mu(1)*mu(2).^2 ",
" exp(mu(2))-mu(1) ",
" cos(mu(3))+sin(10*mu(1)) "];
53 Px0 = dscomponents.AffineInitialValue;
54 Px0.addMatrix(funs[2],10*(s.rand(dim,1)-.5));
55 Px0.addMatrix(funs[3],10*(s.rand(dim,1)-.5));
63 Ap = dscomponents.AffLinCoreFun;
65 diff = spdiags([e -2*e e], -1:1, dim, dim);
66 diff(1,2) = -1; diff(end,end-1) = -1;
67 Ap.addMatrix(funs[1], diff);
69 Ap.addMatrix(funs[
k], 0.1*(
Utils.
sprand(dim,dim,spfac,s)-.5));
74 Cp = dscomponents.AffLinOutputConv;
75 Cp.addMatrix(
" mu(1) ",[1; zeros(dim-1,1)]^
t);
76 Cp.addMatrix(
" 1-mu(1) ",[0; 1; zeros(dim-2,1)]^
t);
80 mu = m.getRandomParam;
81 [
t,y,ct,x] = m.simulate(mu);
82 fprintf(
" Simulation time: %g\n ",ct);
87 u1 = @(
t)-200*exp(-(
t-.5).^2/3);
88 u2 = @(
t)200*sin(10*
t).*(
t>.3);
89 m.System.Inputs[1] = u1;
90 m.System.Inputs[2] = u2;
91 Bp = dscomponents.AffLinInputConv;
92 Bp.addMatrix(
" mu(2)/2 ",[1; zeros(dim-1,1)]);
93 Bp.addMatrix(
" 1-mu(2)/2 ",[0; 1; zeros(dim-2,1)]);
97 mu = m.getRandomParam;
98 [~,y] = m.simulate(mu);
99 [
t,y_u1] = m.simulate(mu,1);
106 s = sampling.RandomSampler;
116 s = spacereduction.PODGreedy;
119 s.MaxSubspaceSize= 20;
124 s.IncludeAxData=
true;
128 s.IncludeBSpan=
true;
134 m.off1_createParamSamples;
135 m.off2_genTrainingData;
136 m.off3_computeReducedSpace;
144 mu = m.getRandomParam;
146 r = m.buildReducedModel;
149 [~,yr] = r.simulate(mu,1);
150 [
t,y] = m.simulate(mu,1);
159 ma.plotReductionOverview;
160 ma.compareRedFull(mu,1);
ModelAnalyzer: Analysis tools for reduced models and approximations.
Collection of generally useful functions.
function Basics2_Parametrized()
Basics2_Parametrized:
static function S = sprand(integer n,integer m,double dens,RandStream rs)
Creates a random sparse matrix with given density (approximately).