⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lfdemo.m

📁 潮流计算
💻 M
字号:
% ldfwdemo.m
% m file to demo loadflow solutions
% a loadflow report is placed in lf_rep.txt if requested

clear
clear global
% global variables
%pst_var                        %为电力系统仿真定义全局变量
global gen_chg_idx             %定义一个全局变量

disp('loadflow demo program')  %显示loadflow demo program
% load input data from m.file  负荷的输入的数据在m.file

[dfile,pathname]=uigetfile('d*.m','Select Data File');%弹出一个对话框,选择m文件
if pathname == 0    %如果没有选择路径,提示错误
  error(' you must select a valid data file')
else
  lfile =length(dfile);%dfile是文件名,lfile是dfile的长度
  
  dfile = lower(dfile(1:lfile-2));% strip off .m and convert to lower case去掉".m"其他文件名转换成小写
  eval(dfile);%~~~~~~~~~~~~~~~~~~~~~~~~~~?
end
% check for valid dynamic data file检查有效动态数据文件
if isempty(bus)
   error(' the selected file is not a valid data file') %如果没有节点数据,显示错误
end
%输出结果,是否需要潮流计算结果的报告
answer=input('Do you need a load-flow solution report?  [y/n]n >>     ','s');%把输入赋值给answer
if ~isempty(answer)%如果answer不是空
   if answer == 'Y';answer = 'y';end%输入Y,则ans是y
   if answer == 'y'; diary lf_rep.txt; end%如果ans是y,显示报告
end
nbus = length(bus(:,1)); % 把矩阵bus的第一列元素的个数赋值给nbus
gen_chg_idx = ones(nbus,1);%nbus*1的1阵
[bus_sol,line_sol,line_flow] = loadflow(bus,line,1e-9,10, ...
                               1.0,answer,2);
%调用loadflowfunction [bus_sol,line_sol,line_flow] = loadflow(bus,line,tol,iter_max,acc,display,flag)
if ~isempty(answer)
   if answer=='y'%如果ans=y
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~为什么分Y和y有不同?为什么不是y和n?
      diary off%suspends it
      disp('A load-flow study report is in lf_rep.txt')%显示()
   end
end


flag = 0;%标志位置0
while(flag == 0)%当flag=0 显示一下内容:
  disp('You can examine the system data')
  disp('Type 1 to see initial bus data')
  disp('     2 to see modified line data')
  disp('     3 to see solved load flow bus solution')
  disp('     4 to see line flow')
  disp('     5 to see bus voltage magnitude profile')
  disp('     6 to see bus voltage phase profile')
  disp('     0 to quit')
  sel = input('enter selection >> ');%将输入()赋值给sel
  if isempty(sel);sel=0;end%如果sel为空,sel设为0   (=是赋值;==是等于)
  if sel == 1              %如果sel=1,显示:
      disp('                                   Initial Bus Data')
      disp('                                      GENERATION             LOAD')
      disp('       BUS     VOLTS     ANGLE      REAL  REACTIVE      REAL  REACTIVE ')
      disp(bus(:,1:7))
      disp('paused: press any key to continue')
      pause%等待用户按任意键继续
    elseif sel == 2
      disp('                               Modified Line  Data')
      disp(line_sol)
      disp('paused: press any key to continue')
      pause%等待用户按任意键继续
    elseif sel == 3
      disp('                                    Solved Bus Data')
      disp('                                      GENERATION             LOAD')
      disp('       BUS     VOLTS     ANGLE      REAL  REACTIVE      REAL  REACTIVE ')
      disp(bus_sol(:,1:7))
      disp('paused: press any key to continue')
      pause
    elseif sel == 4
      disp('                  solved Line Flows')
      disp('                      LINE FLOWS                     ')
      disp('      LINE  FROM BUS    TO BUS      REAL  REACTIVE   ')
      disp(line_flow)
      disp('paused: press any key to continue')
      pause
    elseif sel == 5
      bar(bus_sol(:,2))%画柱状图
      title('bus voltage magnitude profile')%标题
      xlabel('internal bus number')%x轴
      ylabel('voltage in pu')%y轴
      disp('paused: press any key to continue')%显示( )
      pause
    elseif sel == 6
      bar(bus_sol(:,3))%画柱状图
      title('bus voltage phase profile')
      xlabel('internal bus number')
      ylabel('phase in degrees')
      disp('paused: press any key to continue')
      pause
    elseif sel == 0
      flag = 1;%将flag赋值0
    else
      error('invalid selection')%错误提示:无效选择
  end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -