风速数据采用间隔15min的48个点(即12个小时)的数据直接预测间隔15min的16个点。并通过神经网络算法夫妻输出功率进行预测。
完整程序:
load fengsu5min; %用间隔15min的48个点(即12个小时)的数据直接预测间隔15min的16个点
load gonglv5min;
% load wendu5min;
% load fengxiang5min;
% for i=1:8929
% zhengxuan(i)=sin(fengxiang5min(i)*pi/180);
% end
b=fengsu5min;
c=gonglv5min;
% f=zhengxuan;
% d=wendu5min;
% e=fengxiang5min;
mi1=min(b);
ma1=max(b);
b=(b-mi1)/(ma1-mi1);
mi2=min(c);
ma2=max(c);
c=(c-mi2)/(ma2-mi2);
% mi5=min(f);
% ma5=max(f);
% f=(f-mi5)/(ma5-mi5);
% mi3=min(d);
% ma3=max(d);
% d=(d-mi3)/(ma3-mi3);
% mi4=min(e);
% ma4=max(e);
% e=(e-mi4)/(ma1-mi4);
for i=1:8900
p(i,:)=[b(i),b(i+1),b(i+2),b(i+3),b(i+4),b(i+5)];
% ,b(i+7),b(i+8),b(i+9),b(i+10),b(i+11),b(i+12),b(i+13),b(i+14),b(i+15)
% ,f(i),f(i+1),f(i+2),f(i+3),f(i+4),f(i+5)
% ,d(i),d(i+1),d(i+2),d(i+3),d(i+4),e(i),e(i+1),e(i+2),e(i+3),e(i+4)
% ,b(i+16),b(i+17),c(i),c(i+1),c(i+2),c(i+3),c(i+4),c(i+5)
end
for i=6:8912
a(i,:)=[c(i)];
end
for k=1:48
p_train=p(1:2874+k,:);
t_train=a(6:2879+k,:);
p_test=p(2875+k,:);
t_test=a(2880+k,:);
p_train=p_train';
t_train=t_train';
p_test=p_test';
t_test=t_test';
% nn=[31 2];
% for i=1:2
threshold=[0 1;0 1;0 1;0 1;0 1;0 1];
net=newelm(threshold,[13,1],{'tansig','purelin'});
net.trainParam.epochs=1000;
net.trainParam.show=20;
net=init(net);
net=train(net,p_train,t_train);
y=sim(net,p_test);
y1=y*(ma2-mi2)+mi2;
y2(k)=y1;
t_test1=t_test*(ma2-mi2)+mi2;
t_test2(k)=t_test1;
error(k)=t_test2(k)-y2(k);
end
% end
plot(y2,':k')
hold on
plot(t_test2,'k')
legend('预测值','实际值')
% plot(error,'-ro','linewidth',2);
% hold on;
% mse(error);
% fprintf('error= %f\n', error);
% plot(y1,':k')
% hold on;
% plot(t_test1,'k')
% error;
rate1=(sum((error./1500).^2)/48)^(1/2)
rate2=(sum((error.^2).^(1/2)))/48/1500
y3=mean(y2);
t_test3=mean(t_test2);
for k=1:48
error1(k)=y2(k)-y3;
error2(k)=t_test2(k)-t_test3;
end
rate3=sum(error1.*error2);
rate4=(sum(error1.^2)*sum(error2.^2))^(1/2);
rate5=rate3/rate4
% bk=0;
% for i=1:16
% if error(i)/1600<=0.15
% bk(i)=1;
% else
% bk(i)=0;
% end
% end
% rate2(k)=sum(bk)/16
% ans(error)
% for i=1:16
% f(i)=e(i)/t_test(i);
% end
% sum(f(i))/16
预测结果:
风速及功率数据:
基于神经网络的风功率预测方法(MATLAB实现)-Matlab文档类资源-CSDN文库