%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Program "chapter3splines" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab program for spline-based decomposition of energy intensity in two effects (structural, intensity).
% Written by Paula F. Gonzalez, Manuel Landajo & Maria J. Presno (2014).
% NOTE: It requires the splines toolbox of Matlab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
clear;
%
[n,N,E,Y,dates]=dataread('c:\datachapter3.csv');
%
%
% Type of decomposition ('additiv' = additive), ('multipl' = multiplicative):
tipo='multipl';
%tipo='additiv';
%
%
% Numeric integration parameter (no. of bins per year):
bins=2000;
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=E;
y=Y;
clear E;
clear Y;
%
T=n-1;
numk=N;
t=[0:(1/T):1]';
TTT=T*bins;
h = 1/TTT;
tt =[0:h:1];
largo0=TTT+1;
% Spline interpolants for sectoral energy consumptions (x) and productions (y):
xt=[zeros(largo0,1)];
yt=[zeros(largo0,1)];
for k=1:numk
xin=spline(t,x(:,k),tt);
yin=spline(t,y(:,k),tt);
xt=[xt,xin'];
yt=[yt,yin'];
end
xt=[xt(:,2:(numk+1))];
yt=[yt(:,2:(numk+1))];
% Interpolated totals, sector energy intensities and production shares:
xtot=sum(xt')';
ytot=sum(yt')';
Itot=[xtot./ytot];
for j=1:numk
I(:,j)=xt(:,j)./yt(:,j);
S(:,j)=yt(:,j)./ytot;
difI(:,j)=diff(I(:,j))/h;
difS(:,j)=diff(S(:,j))/h;
end
largoderi=length(difI(:,1));
% Real energy intensities:
totx=sum(x')';
toty=sum(y')';
Iverdatot=totx./toty;
% Initial an final intensities:
I0=Itot(1)
I1=Itot(largo0)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ADDITIVE DECOMPOSITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if tipo=='additiv'
%
disp('ADDITIVE DECOMPOSITION:')
Variation=I1-I0
%
sumainte=0;
for i=1:largoderi
sumainte=sumainte+difI(i,:)*(S(i,:)'+S(i+1,:)')*h/2;
intenseffect(i,1)=sumainte;
end
intenseffect=[0;intenseffect];
Intensity_effect=sumainte
%
sumainte2=0;
for i=1:largoderi
sumainte2=sumainte2+difS(i,:)*(I(i,:)'+I(i+1,:)')*h/2;
structeffect(i,1)=sumainte2;
end
structeffect=[0;structeffect];
%
Structural_effect=sumainte2
totaleffect=intenseffect+structeffect;
end
%
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MULTIPLICATIVE DECOMPOSITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
if tipo=='multipl'
%
disp('MULTIPLICATIVE DECOMPOSITION:')
Ratio=I1/I0
%
sumainte1=0;
for i=1:largoderi
sumainte1=sumainte1+difI(i,:)*(S(i,:)'+S(i+1,:)')*h/(Itot(i)+Itot(i+1));
intenseffect(i,1)=sumainte1;
end
intenseffect=exp([0;intenseffect]);
Intensity_effect=exp(sumainte1)
%
sumainte3=0;
for i=1:largoderi
sumainte3=sumainte3+difS(i,:)*(I(i,:)'+I(i+1,:)')*h/(Itot(i)+Itot(i+1));
structeffect(i,1)=sumainte3;
end
structeffect=exp([0;structeffect]);
%
Structural_effect=exp(sumainte3)
totaleffect=intenseffect.*structeffect;
end
% PLOTS:
t=dates;
TTT=T*bins;
tt =[dates(1):(dates(n)-dates(1))/TTT:dates(n)];
%
SUBPLOT(2,3,1), plot(t,x,'*',tt,xt,'-')
title('Sector energy consumptions')
axis tight
SUBPLOT(2,3,2), plot(t,y,'*',tt,yt,'-')
title('Sector productions')
axis tight
legend('Agric','Ind','Serv','Transp')
lll=length(structeffect);
tt=dates(1):((dates(n)-dates(1))/(lll-1)):dates(n);
SUBPLOT(2,3,4), plot(tt,structeffect)
title('Structural effect')
axis tight
SUBPLOT(2,3,5), plot(tt,intenseffect)
title('Intensity effect')
axis tight
SUBPLOT(2,3,6),
plot(tt,totaleffect)
title('Total effect')
axis tight
'SECTORAL ANALYSIS'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
t=[0:(1/T):1];
h = 1/TTT;
tt =[0:h:1];
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ADDITIVE DECOMPOSITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if tipo=='additiv'
disp('ADDITIVE DECOMPOSITION:')
I0=Itot(1)
I1=Itot(largo0)
Variation=I1-I0
%
% 1) Intensity effects:
for j=1:numk
sumainte=0;
for i=1:largoderi
sumainte=sumainte+difI(i,j)*(S(i,j)'+S(i+1,j)')*h/2;
end
Intensitysect(j)=sumainte;
end
%
% 2) Structural effects:
for j=1:numk
sumainte2=0;
for i=1:largoderi
sumainte2=sumainte2+difS(i,j)*(I(i,j)'+I(i+1,j)')*h/2;
end
Structuralsect(j)=sumainte2;
end
%
Intensity_effect=sum(Intensitysect);
Structural_effect=sum(Structuralsect);
Total_effect=Intensity_effect+Structural_effect;
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MULTIPLICATIVE DECOMPOSITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
if tipo=='multipl'
%
disp('MULTIPLICATIVE DECOMPOSITION:')
I0=Itot(1)
I1=Itot(largo0)
Ratio=I1/I0
%
% 1) Intensity effect:
for j=1:numk
sumainte1=0;
for i=1:largoderi
sumainte1=sumainte1+difI(i,j)*(S(i,j)'+S(i+1,j)')*h/(Itot(i)+Itot(i+1));
end
Intensitysect(j)=exp(sumainte1);
end
%
% 2) Structural effect:
for j=1:numk
sumainte3=0;
for i=1:largoderi
sumainte3=sumainte3+difS(i,j)*(I(i,j)'+I(i+1,j)')*h/(Itot(i)+Itot(i+1));
end
Structuralsect(j)=exp(sumainte3);
end
%
Intensity_effect=prod(Intensitysect);
Structural_effect=prod(Structuralsect);
Total_effect=Intensity_effect*Structural_effect;
end
%
disp('SECTORAL INTENSITY EFFECTS:')
disp('Agric Ind Serv Transp')
disp(Intensitysect)
disp('SECTORAL STRUCTURAL EFFECTS:')
disp('Agric Ind Serv Transp')
disp(Structuralsect)
disp('OVERALL EFFECTS:')
Intensity_effect
Structural_effect
Total_effect