首页 > 行业资讯 > 【物理应用】工程供配电系统含Matlab源码

【物理应用】工程供配电系统含Matlab源码

时间:2022-05-01 来源: 浏览:

【物理应用】工程供配电系统含Matlab源码

天天Matlab 天天Matlab
天天Matlab

TT_Matlab

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,完整matlab代码或者程序定制加qq1575304183。

收录于合集 #物理应用matlab源码 23个

1 简介

为了提高电气工程专业学生的理论联系实际能力,本文介绍了Matlab仿真软件基本教学内容,重点阐述了Matlab软件在"自动控制理论"和"电力系统分析"这两门课程中的应用。经过教学实践证明,在电气工程专业教学中应用Matlab仿真软件是非常有必要的,利用该软件可以系统地让学生掌握系统设计方法和电气工程学科专业知识,从而提高学生分析和解决实际问题的能力。

2 部分代码

function varargout = niulafa(varargin) % NIULAFA M-file for niulafa.fig % NIULAFA, by itself, creates a new NIULAFA or raises the existing % singleton*. % % H = NIULAFA returns the handle to a new NIULAFA or the handle to % the existing singleton*. % % NIULAFA( ’CALLBACK’ ,hObject,eventData,handles,...) calls the local % function named CALLBACK in NIULAFA.M with the given input arguments. % % NIULAFA( ’Property’ , ’Value’ ,...) creates a new NIULAFA or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before niulafa_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to niulafa_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 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct(’gui_Name’, mfilename, ... ’gui_Singleton’, gui_Singleton, ... ’gui_OpeningFcn’, @niulafa_OpeningFcn, ... ’gui_OutputFcn’, @niulafa_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 niulafa is made visible. function niulafa_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 niulafa (see VARARGIN) % Choose default command line output for niulafa handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes niulafa wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = niulafa_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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); end % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,’ String ’) returns listbox1 contents as cell array % contents{get(hObject,’ Value ’)} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); end % --- Executes on selection change in listbox2. function listbox2_Callback(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,’ String ’) returns listbox2 contents as cell array % contents{get(hObject,’ Value ’)} returns selected item from listbox2 % --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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) nPQ=str2num(get(handles.edit1,’string’)); nPV=str2num(get(handles.edit3,’string’)); n=nPQ+nPV+1; load Ps.txt; load Qs.txt; load Us.txt; % nl nr R X Bl Br load zdata.txt; % nx B load xdata.txt; dPQU=1; % ì nl=zdata(:,1); nr=zdata(:,2); R=zdata(:,3); X=zdata(:,4); Bl=zdata(:,5); Br=zdata(:,6); nx=xdata(:,1); Bx=xdata(:,2); nbr=length(zdata(:,1)); nbrx=length(xdata(:,1)); Z=R+j*X; y=ones(nbr,1)./Z; Y=zeros(n,n); % ¨¨ for ii=1:nbr Y(nl(ii),nr(ii))= Y(nl(ii),nr(ii))-y(ii); Y(nr(ii),nl(ii))= Y(nl(ii),nr(ii)); end % for ii=1:n for jj=1:nbr if nl(jj)==ii|nr(jj)==ii Y(ii,ii)=Y(ii,ii)+y(jj); end end end for ii=1:nbr Y(nl(ii),nl(ii))= Y(nl(ii),nl(ii))+j*Bl(ii); Y(nr(ii),nr(ii))= Y(nr(ii),nr(ii))+j*Br(ii); end for ii=1:nbrx Y(nx(ii),nx(ii))=Y(nx(ii),nx(ii))+j*Bx(ii); end % ¨¨GB G=real(Y); B=imag(Y); Y e=real(Us); f=imag(Us); k=0; delta=str2num(get(handles.edit11,’string’)); while dPQU>delta %ìdP dP=zeros(n-1,1); for ii=1:n-1 t=0; for jj=1:n t=t+conj(Y(ii,jj))*(e(jj)-j*f(jj)); end dP(ii)=Ps(ii)-real(t*(e(ii)+j*f(ii))); end %ìdQ dQ=zeros(nPQ,1); for ii=1:nPQ t=0; for jj=1:n t=t+conj(Y(ii,jj))*(e(jj)-j*f(jj)); end dQ(ii)=Qs(ii)-imag(t*(e(ii)+j*f(ii))); end %ìdU^2 dU2=zeros(nPV,1); ii=1:nPV; dU2(ii)=abs(Us(ii+nPQ))^2-abs(e(ii+nPQ)+j*f(ii+nPQ))^2; dS=[dP;dQ;dU2]; dPQU=max(abs(dS)); if(dPQU>0.00001) k=k+1; % Jacob=zeros(2*(n-1),2*(n-1)); %P¨¨ for ii=1:n-1 mid1=0; mid2=0; for jj=1:n if ii~=jj&&jj<n Jacob(ii,2*jj-1)=-(G(ii,jj)*e(ii)+B(ii,jj)*f(ii)); Jacob(ii,2*jj)=B(ii,jj)*e(ii)-G(ii,jj)*f(ii); end mid1=mid1+G(ii,jj)*f(jj)+B(ii,jj)*e(jj); mid2=mid2+G(ii,jj)*e(jj)-B(ii,jj)*f(jj); end Jacob(ii,2*ii-1)=-mid2-G(ii,ii)*e(ii)-B(ii,ii)*f(ii); Jacob(ii,2*ii)=-mid1+B(ii,ii)*e(ii)-G(ii,ii)*f(ii); end %Q¨¨ for ii=1:nPQ mid1=0; mid2=0; for jj=1:n if ii~=jj&&jj<n Jacob(ii+n-1,2*jj-1)=B(ii,jj)*e(ii)-G(ii,jj)*f(ii); Jacob(ii+n-1,2*jj)=G(ii,jj)*e(ii)+B(ii,jj)*f(ii); end mid1=mid1+G(ii,jj)*f(jj)+B(ii,jj)*e(jj); mid2=mid2+G(ii,jj)*e(jj)-B(ii,jj)*f(jj); end Jacob(ii+n-1,2*ii-1)=mid1+B(ii,ii)*e(ii)-G(ii,ii)*f(ii); Jacob(ii+n-1,2*ii)=-mid2+G(ii,ii)*e(ii)+B(ii,ii)*f(ii); end %U2¨¨ for ii=nPQ+1:n-1 Jacob(ii+n-1,2*ii-1)=-2*e(ii); Jacob(ii+n-1,2*ii)=-2*f(ii); end dU=-inv(Jacob)*dS; de=zeros(n-1,1); df=zeros(n-1,1); ii=1:n-1; de(ii)=dU(2*ii-1); df(ii)=dU(2*ii); e(ii)=e(ii)+de(ii); f(ii)=f(ii)+df(ii); end end% ììì U=e+j*f; % PVQ P=zeros(n,1); Q=zeros(n,1); for ii=1:nPV t=0; for jj=1:n t=t+conj(Y(ii+nPQ,jj))*(e(jj)-j*f(jj)); end Q(ii+nPQ)=imag(t*(e(ii+nPQ)+j*f(ii+nPQ))); end % t=0; for jj=1:n t=t+conj(Y(n,jj))*(e(jj)-j*f(jj)); end P(n)=real(t*(e(n)+j*f(n))); Q(n)=imag(t*(e(n)+j*f(n))); ii=1:n-1; P(ii)=Ps(ii); ii=1:nPQ; Q(ii)=Qs(ii); % ¨¨ Sij=zeros(nbr,1); Sji=zeros(nbr,1); dSij=zeros(nbr,1); for ii=1:nbr Sij(ii)=U(nl(ii))*(conj(U(nl(ii)))*(-j*Bl(ii))+(conj(U((nl(ii))))-conj(U((nr(ii)))))*conj(y(ii))); Sji(ii)=U(nr(ii))*(conj(U(nr(ii)))*(-j*Br(ii))+(conj(U((nr(ii))))-conj(U((nl(ii)))))*conj(y(ii))); dSij(ii)=Sij(ii)+Sji(ii); end nn=[1:n]’; nefPQ=[nn e f P Q]; nefPQ=num2str(nefPQ,’%-10.4f’); Pij=real(Sij);Qij=imag(Sij); Pji=real(Sji);Qji=imag(Sji); dPij=real(dSij);dQij=imag(dSij); S=[nl nr Pij Qij Pji Qji dPij dQij]; S=num2str(S,’%-10.4f’); set(handles.listbox1,’string’,nefPQ) set(handles.listbox2, ’string’,S) set(handles.edit9,’string’,num2str(k)) % --- 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) close(gcf); run(’kechengsheji’); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); end % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’niulafa.txt’); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); end % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’Us.txt’); % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’Ps.txt’); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’Qs.txt’); % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’zdata.txt’); % --- Executes on button press in pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(’xdata.txt’); 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 % --- 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 set(hObject,’BackgroundColor’,’white’); else set(hObject,’BackgroundColor’,get(0,’defaultUicontrolBackgroundColor’)); end

3 仿真结果

4 参考文献

[1]张惠萍. MATLAB在供电系统仿真中的研究与应用[J]. 微计算机信息, 2012(1):2.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐