| 1 |
function simtanzphi(X,k,nvar,U); |
| 2 |
% simtanzphi(X,k,nvar,U) |
| 3 |
% Recursive function with global output argument ZPHI |
| 4 |
% Export ZPHI: PHI_k--the span of proj(R(k))(w(a(i))|i~=k), whose rank determines |
| 5 |
% the degree of simultaneity |
| 6 |
% |
| 7 |
% X: nvar-by-nvar matrix so that the 1st k columns are orthonormal |
| 8 |
% k: <=nvar, orthonormal columns |
| 9 |
% nvar: number of variables |
| 10 |
% U: nvar-by-1 cell. Each cell contains a set of orthonormal bases for the ith |
| 11 |
% column of idmat0s (restriction or R(i)) |
| 12 |
%----------- |
| 13 |
% ZPHI: global variable PHI_k--the span of proj(R(k))(w(a(i))|i~=k), whose rank determines |
| 14 |
% the degree of simultaneity |
| 15 |
% |
| 16 |
% |
| 17 |
% Copyright (C) 1997-2012 Daniel Waggoner and Tao Zha |
| 18 |
% |
| 19 |
% This free software: you can redistribute it and/or modify |
| 20 |
% it under the terms of the GNU General Public License as published by |
| 21 |
% the Free Software Foundation, either version 3 of the License, or |
| 22 |
% (at your option) any later version. |
| 23 |
% |
| 24 |
% It is distributed in the hope that it will be useful, |
| 25 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
% GNU General Public License for more details. |
| 28 |
% |
| 29 |
% If you did not received a copy of the GNU General Public License |
| 30 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 31 |
% |
| 32 |
|
| 33 |
global ZPHI |
| 34 |
|
| 35 |
if k<nvar |
| 36 |
V=[X(:,1:k) U{k+1}]; |
| 37 |
[Q,R,eindx]=qr(V,0); % eindx: index vector |
| 38 |
Q1=Q; |
| 39 |
Q1(:,1:k) = Q(:,find(eindx<=k)); % keep the first k col's in V in Q1 |
| 40 |
jnk = find(eindx>k); |
| 41 |
jnk1=length(Q(1,:))-k; |
| 42 |
Q1(:,k+1:length(Q(1,:))) = Q(:,jnk(1:jnk1)); |
| 43 |
tmp = abs(diag(R)); % largest absoluate value in R |
| 44 |
jnk = find(tmp<max(tmp)*eps); % index for the zero's in R |
| 45 |
if isempty(jnk) |
| 46 |
Y = Q1(:,k+1:length(tmp)); |
| 47 |
else |
| 48 |
Y = Q1(:,k+1:min(jnk)-1); % all meaningful orthonormal columns after Q(1:k) |
| 49 |
end |
| 50 |
% |
| 51 |
for ik=1:length(Y(1,:)) |
| 52 |
X=[X(:,1:k) Y(:,ik)]; |
| 53 |
simtanzphi(X,k+1,nvar,U); |
| 54 |
end |
| 55 |
else |
| 56 |
Xn=X(:,nvar); |
| 57 |
%* Projection of Xn into R{n} |
| 58 |
Xnproj=U{nvar}*(Xn'*U{nvar})'; |
| 59 |
ZPHI=[ZPHI Xnproj]; |
| 60 |
end |