% test of KWW 2012
clear all
%define the working deriction
workhouse='E:\Research\GVCs\data\upstreamness\'
cd(workhouse)

F =xlsread('F.xlsx'); 
D =xlsread('D.xlsx'); 
Y =xlsread('Y.xlsx'); 

ex =xlsread('X.xlsx'); 
im =xlsread('M.xlsx'); 
in =xlsread('in_2.xlsx'); 

I=eye(135,135);
e=ones(135,1);

r=Y./(Y-ex+im-in);

for i=1:135
   D_1(i,:)=D(i,:).*r(i,1);
end

T=((inv(I-D))*D);

upstreamness_1=((inv(I-D_1))*Y)./Y;


%xlswrite('upstreamness.xlsx',upstreamness);
%xlswrite('upstreamness_2.xlsx',upstreamness);

upstreamness_2=((inv(I-D_1)*(inv(I-D_1))*D_1))./((inv(I-D_1)*D_1));

T=inv(I-D_1)



xlswrite('upstreamness_2.xlsx',upstreamness_2);
xlswrite('T.xlsx',T);



