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