MAKEJAC Forms the power flow Jacobian. J = MAKEJAC(MPC) J = MAKEJAC(MPC, FULLJAC) J = MAKEJAC(BASEMVA, BUS, BRANCH, GEN) J = MAKEJAC(BASEMVA, BUS, BRANCH, GEN, FULLJAC) [J, YBUS, YF, YT] = MAKEJAC(MPC) Returns the power flow Jacobian and, optionally, the system admittance matrices. Inputs can be a MATPOWER case struct or individual BASEMVA, BUS, BRANCH and GEN values. Bus numbers must be consecutive beginning at 1 (internal ordering). If the FULLJAC argument is present and true, it returns the full Jacobian (sensitivities of all bus injections w.r.t all voltage angles/magnitudes) as opposed to the reduced version used in the Newton power flow updates. Note: This function builds the Jacobian from scratch, rebuilding the YBUS matrix in the process. You probably don't want to use this in performance critical code. See also MAKEYBUS, EXT2INT
0001 function [J, Ybus, Yf, Yt] = makeJac(baseMVA, bus, branch, gen, fullJac) 0002 %MAKEJAC Forms the power flow Jacobian. 0003 % J = MAKEJAC(MPC) 0004 % J = MAKEJAC(MPC, FULLJAC) 0005 % J = MAKEJAC(BASEMVA, BUS, BRANCH, GEN) 0006 % J = MAKEJAC(BASEMVA, BUS, BRANCH, GEN, FULLJAC) 0007 % [J, YBUS, YF, YT] = MAKEJAC(MPC) 0008 % 0009 % Returns the power flow Jacobian and, optionally, the system admittance 0010 % matrices. Inputs can be a MATPOWER case struct or individual BASEMVA, 0011 % BUS, BRANCH and GEN values. Bus numbers must be consecutive beginning 0012 % at 1 (internal ordering). If the FULLJAC argument is present and true, 0013 % it returns the full Jacobian (sensitivities of all bus injections 0014 % w.r.t all voltage angles/magnitudes) as opposed to the reduced version 0015 % used in the Newton power flow updates. 0016 % 0017 % Note: This function builds the Jacobian from scratch, rebuilding the 0018 % YBUS matrix in the process. You probably don't want to use this 0019 % in performance critical code. 0020 % 0021 % See also MAKEYBUS, EXT2INT 0022 0023 % MATPOWER 0024 % $Id: makeJac.m 1987 2012-01-24 14:44:02Z cvs $ 0025 % by Ray Zimmerman, PSERC Cornell 0026 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0027 % 0028 % This file is part of MATPOWER. 0029 % See http://www.pserc.cornell.edu/matpower/ for more info. 0030 % 0031 % MATPOWER is free software: you can redistribute it and/or modify 0032 % it under the terms of the GNU General Public License as published 0033 % by the Free Software Foundation, either version 3 of the License, 0034 % or (at your option) any later version. 0035 % 0036 % MATPOWER is distributed in the hope that it will be useful, 0037 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0038 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0039 % GNU General Public License for more details. 0040 % 0041 % You should have received a copy of the GNU General Public License 0042 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0043 % 0044 % Additional permission under GNU GPL version 3 section 7 0045 % 0046 % If you modify MATPOWER, or any covered work, to interface with 0047 % other modules (such as MATLAB code and MEX-files) available in a 0048 % MATLAB(R) or comparable environment containing parts covered 0049 % under other licensing terms, the licensors of MATPOWER grant 0050 % you additional permission to convey the resulting work. 0051 0052 if nargin < 4 0053 mpc = baseMVA; 0054 if nargin > 1 0055 fullJac = bus; 0056 else 0057 fullJac = 0; 0058 end 0059 baseMVA = mpc.baseMVA; 0060 bus = mpc.bus; 0061 branch = mpc.branch; 0062 gen = mpc.gen; 0063 elseif nargin < 5 0064 fullJac = 0; 0065 end 0066 0067 %% define named indices into bus, gen, branch matrices 0068 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0069 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0070 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0071 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0072 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0073 0074 %% build Ybus 0075 [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 0076 0077 %% extract voltage 0078 V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA)); 0079 on = find(gen(:, GEN_STATUS) > 0); %% which generators are on? 0080 gbus = gen(on, GEN_BUS); %% what buses are they at? 0081 V(gbus) = gen(on, VG) ./ abs(V(gbus)).* V(gbus); 0082 0083 %% build Jacobian 0084 [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V); 0085 if fullJac 0086 j11 = real(dSbus_dVa); 0087 j12 = real(dSbus_dVm); 0088 j21 = imag(dSbus_dVa); 0089 j22 = imag(dSbus_dVm); 0090 else 0091 %% get bus index lists of each type of bus 0092 [ref, pv, pq] = bustypes(bus, gen); 0093 0094 j11 = real(dSbus_dVa([pv; pq], [pv; pq])); 0095 j12 = real(dSbus_dVm([pv; pq], pq)); 0096 j21 = imag(dSbus_dVa(pq, [pv; pq])); 0097 j22 = imag(dSbus_dVm(pq, pq)); 0098 end 0099 0100 J = [ j11 j12; 0101 j21 j22; ];