Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/nqzdiv.m

raw
1 function [A,B,P,R] = nqzdiv(stake,A,B,V,P)
2 %function [A,B,Q,Z] = nqzdiv(stake,A,B,V,P)
3 %
4 % Takes U.T. matrices A, B, V, and P and rearranges them
5 % so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right
6 % corner, while the output A and B are diagonal, and P*A*R=G0, P*B*R=G1.
7 % Note: the input A and B are U.T.; the output A and B are diagonal.
8 %
9 % Modified by T.Zha, 5/26/97
10 %
11 % Copyright (C) 1997-2012 Tao Zha
12 %
13 % This free software: you can redistribute it and/or modify
14 % it under the terms of the GNU General Public License as published by
15 % the Free Software Foundation, either version 3 of the License, or
16 % (at your option) any later version.
17 %
18 % It is distributed in the hope that it will be useful,
19 % but WITHOUT ANY WARRANTY; without even the implied warranty of
20 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 % GNU General Public License for more details.
22 %
23 % If you did not received a copy of the GNU General Public License
24 % with this software, see <http://www.gnu.org/licenses/>.
25 %
26
27
28 [n jnk] = size(A);
29
30 ald = diag(diag(A)); % d: diagoanl
31 bed = diag(diag(B));
32 R = inv(V);
33
34 root = abs([diag(ald) diag(bed)]);
35 root(:,1) = root(:,1)-(root(:,1)<1.e-13).*(root(:,1)+root(:,2));
36 root(:,2) = root(:,2)./root(:,1);
37 for i = n:-1:1
38 m=0;
39 for j=i:-1:1
40 if (root(j,2) > stake | root(j,2) < -.1)
41 m=j;
42 break
43 end
44 end
45 if (m==0)
46 return
47 elseif (m<i-1)
48 pindx = 1:n; % T.Z., 5/26/97
49 pindx(m)=i-1;
50 pindx(i-1)=m;
51 %*** permutation begins
52 ald = ald(pindx,pindx);
53 bed = bed(pindx,pindx);
54 P = P(:,pindx); % column permutation, T.Z., 5/26/97
55 R = R(pindx,:); % row permutation
56 end
57 end
58
59 %*** return the new Q, Z, A, B
60 A = diag(1./diag(bed));
61 B = diag(1./diag(ald));