1 function [n,nn,nnn] = rb_residual_norm(model, rd, rbsim)
2 % RB_RESIDUAL_NORM Calculate the residual norm of the rb solution rbsim
4 % Andreas Schmidt, 2015
8 A_coeff = model.A_coeff();
9 B_coeff = model.B_coeff();
10 C_coeff = model.C_coeff();
11 E_coeff = model.E_coeff();
12 Q_coeff = model.Q_coeff();
13 R_coeff = model.R_coeff();
15 % Assemble all matrices:
19 % Directly assemble the small R and Q matrices:
20 Q = lincomb_sequence(rd.Q_comp, Q_coeff);
21 R = lincomb_sequence(rd.R_comp, R_coeff);
24 R_ECQCA = zeros(size(PN,1));
25 for i = 1:length(A_coeff)
26 for j = 1:length(C_coeff)
27 for k = 1:length(C_coeff)
28 for l = 1:length(E_coeff)
29 R_ECQCA = R_ECQCA + A_coeff(i)*C_coeff(j)*C_coeff(k)*...
30 E_coeff(l)*estim.M1b{l,k}*Q*estim.M1a{j,i};
36 R_EE = zeros(size(PN,1));
37 for i = 1:length(E_coeff)
38 for j = 1:length(E_coeff)
39 R_EE = R_EE + E_coeff(i)*E_coeff(j)*estim.M8{i,j};
43 R_AA = zeros(size(PN,1));
44 for i = 1:length(A_coeff)
45 for j = 1:length(A_coeff)
46 R_AA = R_AA + A_coeff(i)*A_coeff(j)*estim.M5{i,j};
50 R_BB = zeros(size(PN,1));
51 for i = 1:length(B_coeff)
52 for j = 1:length(B_coeff)
53 R_BB = R_BB + B_coeff(i)*B_coeff(j)*rd.B_comp{i}*invR*rd.B_comp{j}
';
57 R_EA = zeros(size(PN,1));
58 for i = 1:length(A_coeff)
59 for j = 1:length(E_coeff)
60 R_EA = R_EA + A_coeff(i)*E_coeff(j)*estim.M3{i,j};
64 R_ECCE = zeros(size(PN,1));
65 for i = 1:length(C_coeff)
66 for j = 1:length(C_coeff)
67 for k = 1:length(E_coeff)
68 for l = 1:length(E_coeff)
69 R_ECCE = R_ECCE + C_coeff(i)*C_coeff(j)*E_coeff(k)*...
70 E_coeff(l)*estim.M1b{l,j}*Q*estim.M1b{k,i}';
76 R_CCTQCCTQ = zeros(size(estim.M7{1,1}, 1));
77 for i = 1:length(C_coeff)
78 for j = 1:length(C_coeff)
79 for k = 1:length(C_coeff)
80 for l = 1:length(C_coeff)
81 R_CCTQCCTQ = R_CCTQCCTQ + estim.M7{i,j}*Q*estim.M7{k,l}*Q*C_coeff(i)*C_coeff(j)*...
82 C_coeff(k)*C_coeff(l);
88 d = trace(R_CCTQCCTQ);
89 res = d + 4*trace(R_ECQCA*PN) - 4*trace(PN*R_EE*PN*R_BB*PN*R_EA) + ...
90 -2*trace(R_ECCE*PN*R_BB*PN) + trace(R_EE*PN*R_BB*PN*R_EE*PN*R_BB*PN) ...
91 + 2*trace(R_EE*PN*R_AA*PN) + 2*trace(R_EA
'*PN*R_EA'*PN);
96 % Set up the norm of A and the norm of B:
99 for k = 1:length(A_coeff)
100 for l = 1:length(A_coeff)
101 normA = normA + A_coeff(k)*A_coeff(l)*estim.normA{k,l};
106 for k = 1:length(B_coeff)
107 for l = 1:length(B_coeff)
108 normB = normB + B_coeff(k)*B_coeff(l)*estim.normB{k,l};
115 nPhat = sqrt(trace(estim.WtW*PN*estim.WtW*PN));
116 normE = abs(E_coeff(1)*estim.normE);
117 nnn = n / (2*nPhat*normE*normA + sqrt(d) + normE^2*nPhat^2*norm(invR)*normB^2);