2 % This
function calculates gamma.
3 % Simdata must be a high dimensional solution.
5 % This is done by solving the generalized Lyapunov equation
6 % A
' H E + E' H A = - I
7 % and then gamma = || H ||
9 % Andreas Schmidt, 2015
11 % Build the full dimensional system matrices:
14 if ~isfield(model,
'gamma_mode') || strcmp(model.gamma_mode,
'lyap')
15 Y = A-B*B'*sim.Z*sim.Z'*E;
16 gamma = normest(lyap(Y', -eye(model.n), [], E));
17 elseif strcmp(model.gamma_mode, 'power_iteration')
18 % This function is work in progress!!!!!
19 % Initial guess for the "eigenvector"
20 [x0,~,~] = eigs(A,E,1,'sm');
31 % First inner iteration. Integrate the system
32 % E \dotx = (A-BB'PE)x, x(0) = E\x0
35 X = zeros(5000, model.n);
44 M = sparse(diag(diag(E)));
48 [x,~,~,iter,~] = bicgstab(afun(E,A,B,Z,dt), rhs, tol, 200, [], []);
56 dt = dt*0.9*(1e-2/norm(tau))^0.3;
61 if norm(X(k,:)) < 1e-4
66 % Integrate backwards to get gamma:
68 % Perform the "backward" solution:
70 y = zeros(model.n, 1);
77 [y,~,~,~,~] = bicgstab(afun2(E,A,B,Z,dt), rhs, tol, 200, [], [], y);
82 display(['Relative change ', num2str(abs(gamma-e0)/e0)])
83 if abs(gamma-e0)/e0 < 1e-3
87 %sim2 = riccati_simulate_system(model, model_data, 'use_feedback', sim, 'x0', zeros(model.n,1), 'use_rhs', flip(sim1.x), 'nt', 200, 'T', 10);
88 %y = E'\sim2.x(end,:)';
96 function f = afun(E,A,B,Z,dt)
97 f = @(x) E*x - dt*A*x + dt*B*(B'*(Z*(Z'*(E*x))));
99 function f = afun2(E,A,B,Z,dt)
100 f = @(x) E'*x - dt*A'*x + dt*E'*(Z*(Z'*(B*(B'*x))));
function [ E , A , B , C , x0 ] = riccati_assemble_system_matrices(model, model_data)
model_data)
function gamma = riccati_gamma(model, model_data, sim)
This function calculates gamma. Simdata must be a high dimensional solution.