rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
riccati_residual_norm.m
1 function [res, nres] = riccati_residual_norm(model, reduced_data, ...
2  sim_data)
3 %function res = riccati_residual_norm(model, reduced_data, sim_data, full)
4 %
5 % This function calculates the residual norm in a fast way by applying
6 % the online/offline Frobenius norm technique as explained in the paper.
7 %
8 % Outputs:
9 % res ................ The Frobenius norm of the Residual
10 % nres ............... Normalized Residual norm
11 %
12 % Andreas Schmidt, 2015
13 %
14 
15 estim = reduced_data.estim;
16 PN = sim_data.PN;
17 
18 % Calculate the coefficients
19 model.decomp_mode = 2;
20 A_coeff = model.A(model, reduced_data);
21 B_coeff = model.B(model, reduced_data);
22 C_coeff = model.C(model, reduced_data);
23 E_coeff = model.E(model, reduced_data);
24 
25 % Assemble all matrices:
26 R_ECCA = zeros(size(PN,1));
27 for i = 1:length(A_coeff)
28  for j = 1:length(C_coeff)
29  for k = 1:length(C_coeff)
30  for l = 1:length(E_coeff)
31  R_ECCA = R_ECCA + A_coeff(i)*C_coeff(j)*C_coeff(k)*...
32  E_coeff(l)*estim.M1{i,j,k,l};
33  end
34  end
35  end
36 end
37 
38 R_EE = zeros(size(PN,1));
39 for i = 1:length(E_coeff)
40  for j = 1:length(E_coeff)
41  R_EE = R_EE + E_coeff(i)*E_coeff(j)*estim.M8{i,j};
42  end
43 end
44 
45 R_AA = zeros(size(PN,1));
46 for i = 1:length(A_coeff)
47  for j = 1:length(A_coeff)
48  R_AA = R_AA + A_coeff(i)*A_coeff(j)*estim.M5{i,j};
49  end
50 end
51 
52 R_BB = zeros(size(PN,1));
53 for i = 1:length(B_coeff)
54  for j = 1:length(B_coeff)
55  R_BB = R_BB + B_coeff(i)*B_coeff(j)*estim.M2{i,j};
56  end
57 end
58 
59 R_EA = zeros(size(PN,1));
60 for i = 1:length(A_coeff)
61  for j = 1:length(E_coeff)
62  R_EA = R_EA + A_coeff(i)*E_coeff(j)*estim.M3{i,j};
63  end
64 end
65 
66 R_ECCE = zeros(size(PN,1));
67 for i = 1:length(C_coeff)
68  for j = 1:length(C_coeff)
69  for k = 1:length(E_coeff)
70  for l = 1:length(E_coeff)
71  R_ECCE = R_ECCE + C_coeff(i)*C_coeff(j)*E_coeff(k)*...
72  E_coeff(l)*estim.M4{i,j,k,l};
73  end
74  end
75  end
76 end
77 
78 d = 0;
79 res = 0;
80 for i = 1:length(C_coeff)
81  for j = 1:length(C_coeff)
82  for k = 1:length(C_coeff)
83  for l = 1:length(C_coeff)
84  tmp = estim.M7{i,j,k,l}*C_coeff(i)*C_coeff(j)*...
85  C_coeff(k)*C_coeff(l);
86  res = res + tmp;
87  d = d + tmp;
88  end
89  end
90  end
91 end
92 
93 res = res + 4*trace(R_ECCA*PN) - 4*trace(R_EE*PN*R_BB*PN*R_EA*PN) + ...
94  -2*trace(R_ECCE*PN*R_BB*PN) + trace(R_EE*PN*R_BB*PN*R_EE*PN*R_BB*PN) ...
95  + 2*trace(R_EE*PN*R_AA*PN) + 2*trace(R_EA'*PN*R_EA'*PN);
96 
97 res = sqrt(abs(res));
98 nres = res/sqrt(d);