1 function [res, nres] = riccati_residual_norm(model, reduced_data, ...
3 %
function res = riccati_residual_norm(model, reduced_data, sim_data, full)
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.
9 % res ................ The Frobenius norm of the Residual
10 % nres ............... Normalized Residual norm
12 % Andreas Schmidt, 2015
15 estim = reduced_data.estim;
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);
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};
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};
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};
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};
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};
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};
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);
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);