Debian Codegraph @

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

raw
1 function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v)
2 %function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v)
3 %
4 % Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them
5 % so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right
6 % corner, while preserving U.T. and orthonormal properties and Q'AZ' and
7 % Q'BZ'. The columns of v are sorted correspondingly.
8 %
9 % by Christopher A. Sims
10 % modified (to add v to input and output) 7/27/00
11 %
12 % Copyright (C) 1997-2012 Christopher A. Sims
13 %
14 % This free software: you can redistribute it and/or modify
15 % it under the terms of the GNU General Public License as published by
16 % the Free Software Foundation, either version 3 of the License, or
17 % (at your option) any later version.
18 %
19 % It is distributed in the hope that it will be useful,
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 % GNU General Public License for more details.
23 %
24 % If you did not received a copy of the GNU General Public License
25 % with this software, see <http://www.gnu.org/licenses/>.
26 %
27
28 vin = nargin==6;
29 if ~vin
30 v=[];
31 end
32 [n jnk] = size(A);
33 root = abs([diag(A) diag(B)]);
34 root(:,1) = root(:,1)-(root(:,1)<1.e-13).*(root(:,1)+root(:,2));
35 root(:,2) = root(:,2)./root(:,1);
36 for i = n:-1:1
37 m=0;
38 for j=i:-1:1
39 if (root(j,2) > stake | root(j,2) < -.1)
40 m=j;
41 break
42 end
43 end
44 if (m==0)
45 return
46 end
47 for k=m:1:i-1
48 [A B Q Z] = qzswitch(k,A,B,Q,Z);
49 tmp = root(k,2);
50 root(k,2) = root(k+1,2);
51 root(k+1,2) = tmp;
52 if vin
53 tmp=v(:,k);
54 v(:,k)=v(:,k+1);
55 v(:,k+1)=tmp;
56 end
57 end
58 end