📄 output.m
字号:
function [Ploss,Qloss] = output(baseMVA, bus, gen, branch, f, success);
%PRINTOPF Prints optimal power flow results.
% printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt) prints
% powerflow results to fd (a file descriptor which defaults to STDOUT).
% mpopt is a MATPOWER options vector (see 'help mpoption' for details).
% Uses default options if this parameter is not given. The objective
% function value is given in f and the elapsed time (seconds to compute
% opf) in et.
% MATPOWER Version 2.0
% by Ray Zimmerman, PSERC Cornell 12/24/97
% Copyright (c) 1996, 1997 by Power System Engineering Research Center (PSERC)
% See http://www.pserc.cornell.edu/ for more info.
%% ----- define named indices into bus, gen, branch matrices
PQ=1; PV=2; REF=3; NONE=4; BUS_I=1; BUS_TYPE=2; PD=3; QD=4; GS=5; BS=6; BUS_AREA=7;
VM=8; VA=9; BASE_KV=10; ZONE=11; VMAX=12; VMIN=13; LAM_P=14; LAM_Q=15; MU_VMAX=16; MU_VMIN=17;
GEN_BUS=1; PG=2; QG=3; QMAX=4; QMIN=5; VG=6; MBASE=7; GEN_STATUS=8; PMAX=9; PMIN=10;
MU_PMAX=11; MU_PMIN=12; MU_QMAX=13; MU_QMIN=14; % MU: KT multiplier
F_BUS=1; T_BUS=2; BR_R=3; BR_X=4; BR_B=5; % standard notation (in input)
RATE_A=6; RATE_B=7; RATE_C=8; TAP=9; SHIFT=10; BR_STATUS=11; % standard notation (in input)
PF=12; QF=13; PT=14; QT=15; MU_SF=16; MU_ST=17; % MU_SF:idx of MU on MVA lim at f bus (in opf)
%% constant
j = sqrt(-1);
%% internal bus number
e2i = zeros(max(bus(:, BUS_I)), 1); %% need internal bus numbering for a second
e2i(bus(:, BUS_I)) = [1:size(bus, 1)]';
%% parameters
nb = size(bus, 1); %% number of buses
nl = size(branch, 1); %% number of branches
ng = size(gen, 1); %% number of generators
ties = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= bus(e2i(branch(:, T_BUS)), BUS_AREA));
%% area inter-ties
tap = ones(nl, 1); %% default tap ratio = 1 for lines
xfmr = find(branch(:, TAP)); %% indices of transformers
tap(xfmr) = branch(xfmr, TAP); %% include transformer tap ratios
tap = tap .* exp(j*pi/180 * branch(:, SHIFT)); %% add phase shifters
nzld = find(bus(:, PD) | bus(:, QD));
sorted_areas = sort(bus(:, BUS_AREA));
areas = sorted_areas([1; find(diff(sorted_areas))+1]); %% area numbers
na = length(areas); %% number of areas
on = find(gen(:, GEN_STATUS));
V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
loss = baseMVA * abs(V(e2i(branch(:, F_BUS))) ./ tap - V(e2i(branch(:, T_BUS)))) .^ 2 ./ ...
(branch(:, BR_R) - j * branch(:, BR_X));
Ploss=sum(real(loss));
Qloss=sum(imag(loss));
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -