图4 使用ARMA模型对电力系统负荷进行预测曲线
图4 预测误差曲线
由仿真结果分析得,使用ARMA模型对电力系统负荷进行预测,其预测结果与实际结果相比较而言,预测误差较小,在可接受范围内,所以预测结果可以采用。
Matlab程序如下: clc; clear;
x1=xlsread('C:\\Users\\dell\\Desktop\\现代信号\\负荷数据.xls','Sheet1'); x1=x1(:,2);
x2=xlsread('C:\\Users\\dell\\Desktop\\现代信号\\负荷数据.xls','Sheet2'); x2=x2(:,2);
x=[x1;x2]; % 电力系统负荷数据,前168个点为历史数据,后24个点为待预测数据 N1=length(x1); N=length(x); t=1:N; figure;
plot(x);title('电力系统负荷数据');xlabel('时间');ylabel('电力系统负荷');axis tight;
%对原始数据进行去趋势处理,即零均值化、平稳化处理 z1=diff(x); %差分 Y=z1-mean(z1); %零均值
[H,PValue,TestStat,CriticalValue] = adftest(Y); %检验是否为时间平稳序列
figure; plot(Y,'r')
title('平稳化处理后电力系统负荷数据');xlabel('时间'),ylabel('功率');
%计算自相关函数、偏相关函数 figure
subplot(2,1,1)
autocorr(Y); %计算置信度为95%的acf,并画出其自相关函数曲线; subplot(2,1,2)
parcorr(Y); %计算置信度为95%的pacf,并画出其偏自相关函数曲线;
%自相关系数和偏相关系数均拖尾性,所以选择arma模型对电力系统负荷数据进行预测
%估计arma模型参数,以AIC标准来定阶 z=iddata(Y); test = [];
for p = 1:10 %自回归对应PACF,给定滞后长度上限p和q for q = 1:10 %移动平均对应ACF m = armax(z,[p q]);
AIC = aic(m); %armax(p,q),选择对应FPE最小,AIC值最小的模型
test = [test;p q AIC]; end end
for k = 1:size(test,1)
if test(k,3) == min(test(:,3)) %选择AIC值最小的模型 p_test = test(k,1); q_test = test(k,2); break; end end
%建立arma模型检验
m = armax(z(1:168),[p_test q_test]); %armax(p,q),[p_test q_test]对应AIC值最小 figure
e = resid(m,z(1:168)); %拟合做残差分析 plot(e);
figure
subplot(2,1,1)
autocorr(e.OutputData) %置信水平0.95,检验残差的自相关和偏相关函数 subplot(2,1,2)
parcorr(e.OutputData)
[Pr,DWr] = dwtest(e.OutputData,z.OutputData); %检验线性回归残差是否相互独立
if Pr<0.05
disp('can not use this model'); else disp('can use this model'); end
%预测5月5日电力系统负荷数据 p=predict(m,z,1); t=[1:1:191]; po = p.OutputData; figure;
plot(t,z,'r',t,po,'b');
%显示预测值(进行反差分、加平均值) X(1)=x(1); for i=2:192
X(i)=x(i-1)+po(i-1);
end
X=X+mean(po);
t=[1:1:192]; figure;
plot(t,x,'r',t,X,'b');title('使用ARMA模型对电力系统负荷数据进行预测');xlabel('时间');ylabel('电力系统负荷');axis tight;legend('负荷真实值','ARMA预测值'); figure;
subplot(2,1,1); t=[168:1:192];
plot(t,x(168:192),'r',t,X(168:192),'b');title('使用ARMA模型对电力系统负荷数据进行预测');xlabel('时间');ylabel('电力系统负荷');axis tight;legend('负荷真实值','ARMA预测值'); subplot(2,1,2); error=x-X';
plot(t,error(168:192));
title('预测值与真实之误差');xlabel('时间');ylabel('5月5日预测值与真实值误差');axis tight;
题6