clc
clear all
close all
load bloc_note_2.txt
[n,m]=size(bloc_note_2);
consommation2= bloc_note_2';
consommation1=consommation2(:);
figure
plot(consommation2)
figure
plot(consommation1)
hold on
% % moyenne mobile d'ordre 7 IMPAIR
yt=consommation1;
T=length(yt);
k=7;
for i=k:T
t=sum(i-(k-1):i)/k;
mm(t)=(sum(yt((i-(k-1):i),:)))/k;
end
A=[mm 0 0 0];
MM=reshape(A,[m,n])';
% figure
% plot(MM(:,k-1:T-2),'r')
% moyenne mobile d'ordre 4 PAIR
% estimation on variation saisonnerie
%1) difference entre yt et moyenne mobile
stild=bloc_note_2(:,:)-MM(:,:);
%2) moyenne pour chaque colonne B1
for j=1:m;
if j<=m-2
B1(:,j)=[sum(stild(2:end,j))]/(n-1);
else
B1(:,j)=[sum(stild(1:end,j))]/(n-1);
end
end
% 3)moyenne deB1
sjprim=mean(B1);
%4) estimation sj: coefficient saisonnier
sj=B1-sjprim;
sjrep=repmat(sj',n,1);
sjj=sjrep(:);
xijprim=yt-sjrep;
% ajustement model
t=1:T;
p1=polyfit(t,xijprim',1);
% ajuster un polynomede degré n à un jeu de données.
% % % p contient les coefficients en puissance décroissante du polynome
yfit = polyval(p1,t);
a=p1(:,1);
b=p1(:,2);
% prevision
ychapeau=yfit'+sjj;
% ychapeau(:,:)=(trim(:,:)-sjrep(:,:);
figure
plot(yt','o-r')
grid on
hold on
plot(ychapeau,'g')
% prevision
tt=T+1:T+12;
yfit2=(polyval(p1,tt));
ychapeau2=(yfit2+sj)';
yvao=cat(1,ychapeau,ychapeau2);
plot(yvao,'--k')
legend('serie initiale','serie ajustee','prevision')
%calcule de MAPE
W=[sum(abs(ychapeau-yt))]./[sum(yt)];
MAPE=((W)/T)*100