【灰度預(yù)測】基于灰色模型實現(xiàn)電力負(fù)荷預(yù)測含Matlab源碼

1 簡介

以忻州市1994~2004年用電量數(shù)據(jù)為例介紹了灰色預(yù)測技術(shù)在電力系統(tǒng)中的應(yīng)用,并與忻州市1994年至2004年工農(nóng)業(yè)生產(chǎn)總值(不變價)和同期用電量數(shù)據(jù)建立的一元線性回歸模型預(yù)測結(jié)果進(jìn)行了對比分析,進(jìn)一步說明了灰色模型預(yù)測具有較高的置信度和應(yīng)用價值。

2 部分代碼

function varargout = gmgui(varargin)

% GMGUI MATLAB code for gmgui.fig

%? ? ? GMGUI, by itself, creates a new GMGUI or raises the existing

%? ? ? singleton*.

%

%? ? ? H = GMGUI returns the handle to a new GMGUI or the handle to

%? ? ? the existing singleton*.

%

%? ? ? GMGUI('CALLBACK',hObject,eventData,handles,...) calls the local

%? ? ? function named CALLBACK in GMGUI.M with the given input arguments.

%

%? ? ? GMGUI('Property','Value',...) creates a new GMGUI or raises the

%? ? ? existing singleton*.? Starting from the left, property value pairs are

%? ? ? applied to the GUI before gmgui_OpeningFcn gets called.? An

%? ? ? unrecognized property name or invalid value makes property application

%? ? ? stop.? All inputs are passed to gmgui_OpeningFcn via varargin.

%

%? ? ? *See GUI Options on GUIDE's Tools menu.? Choose "GUI allows only one

%? ? ? instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gmgui

% Last Modified by GUIDE v2.5 10-May-2016 08:02:00

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',? ? ? ?mfilename, ...

? ? ? ? ? ? ? ? ? ?'gui_Singleton',? gui_Singleton, ...

? ? ? ? ? ? ? ? ? ?'gui_OpeningFcn', @gmgui_OpeningFcn, ...

? ? ? ? ? ? ? ? ? ?'gui_OutputFcn',? @gmgui_OutputFcn, ...

? ? ? ? ? ? ? ? ? ?'gui_LayoutFcn',? [] , ...

? ? ? ? ? ? ? ? ? ?'gui_Callback',? ?[]);

if nargin && ischar(varargin{1})

? ? gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

? ? [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

? ? gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before gmgui is made visible.

function gmgui_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject? ? handle to figure

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% varargin? ?command line arguments to gmgui (see VARARGIN)

% Choose default command line output for gmgui

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes gmgui wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = gmgui_OutputFcn(hObject, eventdata, handles)?

% varargout? cell array for returning output args (see VARARGOUT);

% hObject? ? handle to figure

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit1 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit1 as a double

global V;

V(1)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit1 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit2_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit2 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit2 as a double

global V;

V(2)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit2 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit3_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit3 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit3 as a double

global V;

V(3)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit3_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit3 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit4_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit4 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit4 as a double

global V;

V(4)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit4_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit4 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit5_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit5 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit5 as a double

global V;

V(5)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit5_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit5 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit6_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit6 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit6 as a double

global V;

V(6)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit6_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit6 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit7_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit7 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit7 as a double

global V;

V(7)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit7 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit8_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit8 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit8 as a double

global V;

V(8)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit8_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit8 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit9_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit9 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit9 as a double

global V;

V(9)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit9_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit9 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit10_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit10 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit10 as a double

global V;

V(10)=str2double(get(hObject,'String'));

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit10_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit10 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

function edit11_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit11 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit11 as a double

global Vnew;

Vnew=str2double(get(hObject,'String'))

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function edit11_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit11 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject? ? handle to pushbutton1 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

clear

%首先完成前十個基礎(chǔ)數(shù)據(jù)的預(yù)測

global V;

syms a b;

A=[a b]';

B=cumsum(V);? % 原始數(shù)據(jù)累加

n=length(V);

for i=1:(n-1)

? ? C(i)=(B(i)+B(i+1))/2;? % 生成累加矩陣

end

% 計算待定參數(shù)的值

for i=1:(n-1)

? ? Y(i)=V(i+1);

end

Y=Y';

E=[-C;ones(1,n-1)];

A=inv(E*E')*E*Y;

A=A';

a=A(1);b=A(2);

% 預(yù)測后續(xù)數(shù)據(jù)

F=[];F(1)=V(1);

for i=2:(n+1)

? ? F(i)=(V(1)-b/a)/exp(a*(i-1))+b/a ;

end

G=[];G(1)=V(1);

for i=2:(n+1)

? ? G(i)=F(i)-F(i-1); %得到預(yù)測出來的數(shù)據(jù)

end?

t1=1:10;

t2=1:11;

G(11)? ? %輸出預(yù)測值

plot(t1,V,'o',t2,G)? %原始數(shù)據(jù)與預(yù)測數(shù)據(jù)的比較

grid

% set(handles.edit16,'string',num2str(G(11)));

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject? ? handle to pushbutton2 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

count=0;

global Vnew V;

? ? count=count+1;

? ? for i=1 :9

? ? ? ? V(i)=V(i+1);

? ? end

?%? V(10)=Vnew;? ??


?B=cumsum(V);? % 原始數(shù)據(jù)累加

n=length(V);

for i=1:(n-1)

? ? C(i)=(B(i)+B(i+1))/2;? % 生成累加矩陣

end

% 計算待定參數(shù)的值

Y=V;Y(1)=[];

Y=Y';

E=[-C;ones(1,n-1)];

A=inv(E*E')*E*Y;

A=A';

a=A(1);b=A(2);

% 預(yù)測后續(xù)數(shù)據(jù)

F=[];F(1)=V(1);

for i=2:(n+1)

? ? F(i)=(V(1)-b/a)/exp(a*(i-1))+b/a ;

end

G=[];G(1)=V(1);

for i=2:(n+1)

? ? G(i)=F(i)-F(i-1); %得到預(yù)測出來的數(shù)據(jù)

end?

t1=1+count:10+count;

t2=1+count:11+count;

% G(11)? ?%輸出預(yù)測值

plot(t1,V,'o',t2,G)? %原始數(shù)據(jù)與預(yù)測數(shù)據(jù)的比較

grid

set(handles.edit16,'string',num2str(G(11)));

function edit16_Callback(hObject, eventdata, handles)

% hObject? ? handle to edit16 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit16 as text

%? ? ? ? str2double(get(hObject,'String')) returns contents of edit16 as a double

% set(handles.edit10,'string',num2str(A(10)));

% set(handles.edit16,'string',G(11));

% --- Executes during object creation, after setting all properties.

function edit16_CreateFcn(hObject, eventdata, handles)

% hObject? ? handle to edit16 (see GCBO)

% eventdata? reserved - to be defined in a future version of MATLAB

% handles? ? empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%? ? ? ?See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

? ? set(hObject,'BackgroundColor','white');

end

3 仿真結(jié)果

4 參考文獻(xiàn)

[1]王永華. 一例基于灰色模型的電力負(fù)荷預(yù)測方法的應(yīng)用[J]. 電力學(xué)報, 2005, 20(3):3.

博主簡介:擅長智能優(yōu)化算法棉饶、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號處理、元胞自動機(jī)世吨、圖像處理究流、路徑規(guī)劃媚媒、無人機(jī)等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流夺英。

部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除滋捶。

完整代碼獲取關(guān)注微信公眾號天天matlab

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末痛悯,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子重窟,更是在濱河造成了極大的恐慌载萌,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件亲族,死亡現(xiàn)場離奇詭異炒考,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)霎迫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進(jìn)店門斋枢,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人知给,你說我怎么就攤上這事瓤帚。” “怎么了涩赢?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵戈次,是天一觀的道長。 經(jīng)常有香客問我筒扒,道長怯邪,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任花墩,我火速辦了婚禮悬秉,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘冰蘑。我一直安慰自己和泌,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布祠肥。 她就那樣靜靜地躺著武氓,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上县恕,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天东羹,我揣著相機(jī)與錄音,去河邊找鬼弱睦。 笑死百姓,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的况木。 我是一名探鬼主播垒拢,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼火惊!你這毒婦竟也來了求类?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤屹耐,失蹤者是張志新(化名)和其女友劉穎尸疆,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體惶岭,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡寿弱,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了按灶。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片症革。...
    茶點故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖鸯旁,靈堂內(nèi)的尸體忽然破棺而出噪矛,到底是詐尸還是另有隱情,我是刑警寧澤铺罢,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布艇挨,位于F島的核電站,受9級特大地震影響韭赘,放射性物質(zhì)發(fā)生泄漏缩滨。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一泉瞻、第九天 我趴在偏房一處隱蔽的房頂上張望楷怒。 院中可真熱鬧,春花似錦瓦灶、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春碉怔,著一層夾襖步出監(jiān)牢的瞬間烘贴,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工撮胧, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留桨踪,地道東北人。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓芹啥,卻偏偏與公主長得像锻离,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子墓怀,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,901評論 2 345

推薦閱讀更多精彩內(nèi)容