rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
rb_residual_norm.m
1 function [n,nn,nnn] = rb_residual_norm(model, rd, rbsim)
2 % RB_RESIDUAL_NORM Calculate the residual norm of the rb solution rbsim
3 %
4 % Andreas Schmidt, 2015
5 %
6 descr = model.descr;
7 
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();
14 
15 % Assemble all matrices:
16 PN = rbsim.PN;
17 estim = rd.estim;
18 
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);
22 invR = inv(R);
23 
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};
31  end
32  end
33  end
34 end
35 
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};
40  end
41 end
42 
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};
47  end
48 end
49 
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}';
54  end
55 end
56 
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};
61  end
62 end
63 
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}';
71  end
72  end
73  end
74 end
75 
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);
83  end
84  end
85  end
86 end
87 
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);
92 
93 n = sqrt(abs(res));
94 nn = n/sqrt(d);
95 
96 % Set up the norm of A and the norm of B:
97 if nargout > 2
98  normA = 0;
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};
102  end
103  end
104  normA = sqrt(normA);
105  normB = 0;
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};
109  end
110  end
111  normB = sqrt(normB);
112 
113 
114 
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);
118 end
119 end