📄 calc.m
字号:
function [delP,delQ,P,Q,conv_flag] = ...
calc(nbus,V,ang,Y,Pg,Qg,Pl,Ql,sw_bno,g_bno,tol)
% Syntax: [delP,delQ,P,Q,conv_flag] =
% calc(nbus,V,ang,Y,Pg,Qg,Pl,Ql,sw_bno,g_bno,tol)
%
% Purpose: calculates power mismatch and checks convergence
% also determines the values of P and Q based on the
% supplied values of voltage magnitude and
% angle计算功率偏差,检查收敛,根据电压赋值和相角决定有功无功
% Version: 2.0 eliminates do loop
% Input: nbus - total number of buses节点数
% bus_type - load_bus(3), gen_bus(2), swing_bus(1)节点类型
% V - magnitude of bus voltage电压值
% ang - angle(rad) of bus voltage电压相角
% Y - admittance matrix导纳矩阵
% Pg - real power of generation发电机有功
% Qg - reactive power of generation发电机无功
% Pl - real power of load负荷有功
% Ql - reactive power of load负荷无功
% sw_bno - a vector having zeros at all swing_bus locations ones otherwise
% 列矢量平衡节点处为0,其他位置为1
% g_bno - a vector having zeros at all generator bus locations ones otherwise
% 列矢量发电机节点处为0,其他位置为1
% tol - a tolerance of computational error精度
%
% Output: delP - real power mismatch有功偏差
% delQ - reactive power mismatch无功偏差
% P - calculated real power计算的有功
% Q - calculated reactive power计算的无功
% conv_flag - 0, converged收敛=1
% 1, not yet converged不收敛=0
%算法:获得当前注入每个节点的电流通过用导纳矩阵左乘节点电压矢量。通过电流和电压可以算出有功和无功功率。
%误差:delP = Pg - Pl - P; delQ = Qg - Ql - Q
% See also:
%
% Calls:
%
% Called By: loadflow
% (c) Copyright 1991 Joe H. Chow - All Rights Reserved
%
% History (in reverse chronological order)
% Version: 2.0
% Author: Graham Rogers
% Date: July 1994
%
% Version: 1.0
% Author: Kwok W. Cheung, Joe H. Chow
% Date: March 1991
%
% ************************************************************
jay = sqrt(-1);
swing_bus = 1;
gen_bus = 2;
load_bus = 3;
% voltage in rectangular coordinate直角坐标下的电压
V_rect = V.*exp(jay*ang); %电压的向量形式
% bus current injection注入的节点电流
cur_inj = Y*V_rect;%电流=导纳×电压
% power output based on voltages 基于电压的功率输出
S = V_rect.*conj(cur_inj);%视在功率=电压×电流的共轭
P = real(S); Q = imag(S);
delP = Pg - Pl - P;%节点有功功率偏差
delQ = Qg - Ql - Q;%节点无功功率偏差
% zero out mismatches on swing bus and generation bus不考虑平衡节点的偏差和发电机节点的无功偏差
delP=delP.*sw_bno;%平衡节点处有功偏差=0
delQ=delQ.*sw_bno;%平衡节点处的无功偏差=0
delQ=delQ.*g_bno;%发电机节点处的无功偏差=0
% total mismatch总偏差
[pmis,ip]=max(abs(delP));%ip是最大有功偏差的位置,pims是列ip中的最大值
[qmis,iq]=max(abs(delQ));%找出最大无功偏差qmin(绝对值)
mism = pmis+qmis;%有功+无功
% 判断是否收敛
if mism > tol, %如果超过限制
conv_flag = 1;%表示不收敛
else
conv_flag = 0;
end
return%返回主程序
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -