rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
detailed_simulation.m
1 function sim_data = detailed_simulation(model, model_data)
2 % sim_data = riccati_detailed_simulation(model, model_data)
3 %
4 % Calculate the full solution for a given problem. This function relies on
5 % the M.E.S.S. package from the MPI!
6 %
7 % sim_data is a structure containing the following information
8 % Z ..................... The low rank factor, P = Z Z'
9 % time .................. Time for the solve
10 %
11 % Andreas Schmidt, 2015
12 sim_data = ARE.SimData;
13 t = tic;
14 
15 % Assemble the matrices:
16 [E,A,B,C,Q,R] = model.assemble(model_data);
17 
18 if ~exist('mess_care', 'file') || model.descr.n < 100 || numel(find(real(eig(R))<0))>0
19  if model.descr.n >= 100
20  warning(['The function mess_care could not be found. ', ...
21  '"care" will be used which can result in very poor performance! ', ...
22  'Please consider downloading the M.E.S.S. package from ', ...
23  'http://www.mpi-magdeburg.mpg.de/projects/mess.'])
24  end
25 
26  sim_data.P = care(full(A),full(B),full(C'*Q*C),full(R),full(B*0),full(E));
27 
28  % Calculate the low rank factor
29  [V,D] = eigs(sim_data.P, min(500,size(A,1)));
30 
31  sim_data.Z = real(V*sqrt(D));
32  sim_data.Z(:, find(diag(sqrt(D)) <= 1e-10)) = [];
33 else
34  K0 = [];
35  if isfield(model_data, 'K_in')
36  K0 = model_data.K_in';
37  end
38 
39  maxnm = 100;
40  maxadi = 200;
41 
42  warning('off','all')
43  Rsqrt = sqrtm(inv(R));
44  Qsqrt = sqrtm(Q);
45 
46  [Z,~] = mess_care(A,B*Rsqrt,Qsqrt*C,[],E);
47 
48  warning('on','all');
49  sim_data.Z = real(Z);
50 end
51 sim_data.time = toc(t);
52 sim_data.K = -inv(R)*((B'*sim_data.Z)*sim_data.Z')*E;
Z
Low rank factor of the solution.
Definition: SimData.m:33
K
The gain matrix:
Definition: SimData.m:47
function sim_data = riccati_detailed_simulation(model, model_data)
sim_data = riccati_detailed_simulation(model, model_data)
P
If the problem was small, we also store the full solution.
Definition: SimData.m:40