Home > matpower4.1 > makeYbus.m

makeYbus

PURPOSE ^

MAKEYBUS Builds the bus admittance matrix and branch admittance matrices.

SYNOPSIS ^

function [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch)

DESCRIPTION ^

MAKEYBUS   Builds the bus admittance matrix and branch admittance matrices.
   [YBUS, YF, YT] = MAKEYBUS(MPC)
   [YBUS, YF, YT] = MAKEYBUS(BASEMVA, BUS, BRANCH)
   
   Returns the full bus admittance matrix (i.e. for all buses) and the
   matrices YF and YT which, when multiplied by a complex voltage vector,
   yield the vector currents injected into each line from the "from" and
   "to" buses respectively of each line. Does appropriate conversions to p.u.
   Inputs can be a MATPOWER case struct or individual BASEMVA, BUS and
   BRANCH values. Bus numbers must be consecutive beginning at 1 (internal
   ordering).

   See also MAKEJAC, MAKESBUS, EXT2INT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch)
0002 %MAKEYBUS   Builds the bus admittance matrix and branch admittance matrices.
0003 %   [YBUS, YF, YT] = MAKEYBUS(MPC)
0004 %   [YBUS, YF, YT] = MAKEYBUS(BASEMVA, BUS, BRANCH)
0005 %
0006 %   Returns the full bus admittance matrix (i.e. for all buses) and the
0007 %   matrices YF and YT which, when multiplied by a complex voltage vector,
0008 %   yield the vector currents injected into each line from the "from" and
0009 %   "to" buses respectively of each line. Does appropriate conversions to p.u.
0010 %   Inputs can be a MATPOWER case struct or individual BASEMVA, BUS and
0011 %   BRANCH values. Bus numbers must be consecutive beginning at 1 (internal
0012 %   ordering).
0013 %
0014 %   See also MAKEJAC, MAKESBUS, EXT2INT.
0015 
0016 %   MATPOWER
0017 %   $Id: makeYbus.m,v 1.17 2010/06/25 17:37:40 ray Exp $
0018 %   by Ray Zimmerman, PSERC Cornell
0019 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0020 %
0021 %   This file is part of MATPOWER.
0022 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0023 %
0024 %   MATPOWER is free software: you can redistribute it and/or modify
0025 %   it under the terms of the GNU General Public License as published
0026 %   by the Free Software Foundation, either version 3 of the License,
0027 %   or (at your option) any later version.
0028 %
0029 %   MATPOWER is distributed in the hope that it will be useful,
0030 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0032 %   GNU General Public License for more details.
0033 %
0034 %   You should have received a copy of the GNU General Public License
0035 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0036 %
0037 %   Additional permission under GNU GPL version 3 section 7
0038 %
0039 %   If you modify MATPOWER, or any covered work, to interface with
0040 %   other modules (such as MATLAB code and MEX-files) available in a
0041 %   MATLAB(R) or comparable environment containing parts covered
0042 %   under other licensing terms, the licensors of MATPOWER grant
0043 %   you additional permission to convey the resulting work.
0044 
0045 if nargin < 3
0046     mpc     = baseMVA;
0047     baseMVA = mpc.baseMVA;
0048     bus     = mpc.bus;
0049     branch  = mpc.branch;
0050 end
0051 
0052 %% constants
0053 nb = size(bus, 1);          %% number of buses
0054 nl = size(branch, 1);       %% number of lines
0055 
0056 %% define named indices into bus, branch matrices
0057 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0058     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0059 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0060     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0061     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0062 
0063 %% check that bus numbers are equal to indices to bus (one set of bus numbers)
0064 if any(bus(:, BUS_I) ~= (1:nb)')
0065     error('buses must appear in order by bus number')
0066 end
0067 
0068 %% for each branch, compute the elements of the branch admittance matrix where
0069 %%
0070 %%      | If |   | Yff  Yft |   | Vf |
0071 %%      |    | = |          | * |    |
0072 %%      | It |   | Ytf  Ytt |   | Vt |
0073 %%
0074 stat = branch(:, BR_STATUS);                    %% ones at in-service branches
0075 Ys = stat ./ (branch(:, BR_R) + 1j * branch(:, BR_X));  %% series admittance
0076 Bc = stat .* branch(:, BR_B);                           %% line charging susceptance
0077 tap = ones(nl, 1);                              %% default tap ratio = 1
0078 i = find(branch(:, TAP));                       %% indices of non-zero tap ratios
0079 tap(i) = branch(i, TAP);                        %% assign non-zero tap ratios
0080 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters
0081 Ytt = Ys + 1j*Bc/2;
0082 Yff = Ytt ./ (tap .* conj(tap));
0083 Yft = - Ys ./ conj(tap);
0084 Ytf = - Ys ./ tap;
0085 
0086 %% compute shunt admittance
0087 %% if Psh is the real power consumed by the shunt at V = 1.0 p.u.
0088 %% and Qsh is the reactive power injected by the shunt at V = 1.0 p.u.
0089 %% then Psh - j Qsh = V * conj(Ysh * V) = conj(Ysh) = Gs - j Bs,
0090 %% i.e. Ysh = Psh + j Qsh, so ...
0091 Ysh = (bus(:, GS) + 1j * bus(:, BS)) / baseMVA; %% vector of shunt admittances
0092 
0093 %% build connection matrices
0094 f = branch(:, F_BUS);                           %% list of "from" buses
0095 t = branch(:, T_BUS);                           %% list of "to" buses
0096 Cf = sparse(1:nl, f, ones(nl, 1), nl, nb);      %% connection matrix for line & from buses
0097 Ct = sparse(1:nl, t, ones(nl, 1), nl, nb);      %% connection matrix for line & to buses
0098 
0099 %% build Yf and Yt such that Yf * V is the vector of complex branch currents injected
0100 %% at each branch's "from" bus, and Yt is the same for the "to" bus end
0101 i = [1:nl; 1:nl]';                              %% double set of row indices
0102 Yf = sparse(i, [f; t], [Yff; Yft], nl, nb);
0103 Yt = sparse(i, [f; t], [Ytf; Ytt], nl, nb);
0104 % Yf = spdiags(Yff, 0, nl, nl) * Cf + spdiags(Yft, 0, nl, nl) * Ct;
0105 % Yt = spdiags(Ytf, 0, nl, nl) * Cf + spdiags(Ytt, 0, nl, nl) * Ct;
0106 
0107 %% build Ybus
0108 Ybus = Cf' * Yf + Ct' * Yt + ...                %% branch admittances
0109         sparse(1:nb, 1:nb, Ysh, nb, nb);        %% shunt admittance

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005