3 % Calculate the (approximate) value of gamma by applying a power iteration
4 % to the matrix H, where H is never formed explicitly but only vector
5 % products are calculated H*x.
7 % Andreas Schmidt, 2016
10 % Stop the power iteration when the relative change is below this
14 % Maximum number of iterations for the power iteration:
15 pi_max_iterations = 100;
17 % Don't accumulate summands with ||s|| <= tol_inner
22 function gamma = calculate(this, model, model_data, dsim,
verbose)
23 if nargin < 5,
verbose=false; end
25 [E,A,B,~,~,R] = model.assemble(model_data);
26 if exist('dsim','var') && ~isempty(dsim)
27 K = -inv(R + B'*dsim.Z*dsim.Z'*B)*B'*dsim.Z*dsim.Z'*A;
29 K = sparse(model.m, model.n);
32 gamma = this.do_power_iteration(A, E, B, K,
verbose);
34 function gen_detailed_data(this, model, model_data)
36 function gen_reduced_data(this, model, detailed_data)
39 function gamma = do_power_iteration(this, A, E, B, K, verbose)
40 if nargin < 3, E = speye(size(A,1)); end
41 if nargin < 6, verbose=false; end
43 tol = this.pi_tolerance;
44 toli = this.tol_inner;
45 maxit = this.pi_max_iterations;
48 x0 = rand(size(A,1), 1);
57 % Do the actual calculation H*x
61 % hx will be the product H*x later on!
69 cache = eU\(eL\(A*cache + B*(K*cache)));
72 % And the backward stuff:
76 tmp = A'*tmp_ + K'*(B'*tmp_);
82 fprintf('Needed %d summands\n', i);
90 gamma_approx = norm(hx);
91 rel_change = abs(gamma_approx-gamma_old)/abs(gamma_old);
93 gamma_old = gamma_approx;
96 fprintf('%d %d\n', [gamma_approx, rel_change]);
98 if rel_change < tol, break, end
100 gamma = gamma_approx;
BASE Basis class for the preparation and calculation of gamma Any subclass should also overwrite the...
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Implementation of the parametric algebraic Riccati equation.