D2SBUS_DV2 Computes 2nd derivatives of power injection w.r.t. voltage. [GAA, GAV, GVA, GVV] = D2SBUS_DV2(YBUS, V, LAM) returns 4 matrices containing the partial derivatives w.r.t. voltage angle and magnitude of the product of a vector LAM with the 1st partial derivatives of the complex bus power injections. Takes sparse bus admittance matrix YBUS, voltage vector V and nb x 1 vector of multipliers LAM. Output matrices are sparse. Example: [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); [Gaa, Gav, Gva, Gvv] = d2Sbus_dV2(Ybus, V, lam); Here the output matrices correspond to: Gaa = (d/dVa (dSbus_dVa.')) * lam Gav = (d/dVm (dSbus_dVa.')) * lam Gva = (d/dVa (dSbus_dVm.')) * lam Gvv = (d/dVm (dSbus_dVm.')) * lam For more details on the derivations behind the derivative code used in MATPOWER information, see: [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and their Derivatives using Complex Matrix Notation", MATPOWER Technical Note 2, February 2010. http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf
0001 function [Gaa, Gav, Gva, Gvv] = d2Sbus_dV2(Ybus, V, lam) 0002 %D2SBUS_DV2 Computes 2nd derivatives of power injection w.r.t. voltage. 0003 % [GAA, GAV, GVA, GVV] = D2SBUS_DV2(YBUS, V, LAM) returns 4 matrices 0004 % containing the partial derivatives w.r.t. voltage angle and magnitude 0005 % of the product of a vector LAM with the 1st partial derivatives of the 0006 % complex bus power injections. Takes sparse bus admittance matrix YBUS, 0007 % voltage vector V and nb x 1 vector of multipliers LAM. Output matrices 0008 % are sparse. 0009 % 0010 % Example: 0011 % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 0012 % [Gaa, Gav, Gva, Gvv] = d2Sbus_dV2(Ybus, V, lam); 0013 % 0014 % Here the output matrices correspond to: 0015 % Gaa = (d/dVa (dSbus_dVa.')) * lam 0016 % Gav = (d/dVm (dSbus_dVa.')) * lam 0017 % Gva = (d/dVa (dSbus_dVm.')) * lam 0018 % Gvv = (d/dVm (dSbus_dVm.')) * lam 0019 % 0020 % For more details on the derivations behind the derivative code used 0021 % in MATPOWER information, see: 0022 % 0023 % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 0024 % their Derivatives using Complex Matrix Notation", MATPOWER 0025 % Technical Note 2, February 2010. 0026 % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 0027 0028 % MATPOWER 0029 % $Id: d2Sbus_dV2.m 1720 2010-11-16 16:05:47Z cvs $ 0030 % by Ray Zimmerman, PSERC Cornell 0031 % Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC) 0032 % 0033 % This file is part of MATPOWER. 0034 % See http://www.pserc.cornell.edu/matpower/ for more info. 0035 % 0036 % MATPOWER is free software: you can redistribute it and/or modify 0037 % it under the terms of the GNU General Public License as published 0038 % by the Free Software Foundation, either version 3 of the License, 0039 % or (at your option) any later version. 0040 % 0041 % MATPOWER is distributed in the hope that it will be useful, 0042 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0043 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0044 % GNU General Public License for more details. 0045 % 0046 % You should have received a copy of the GNU General Public License 0047 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0048 % 0049 % Additional permission under GNU GPL version 3 section 7 0050 % 0051 % If you modify MATPOWER, or any covered work, to interface with 0052 % other modules (such as MATLAB code and MEX-files) available in a 0053 % MATLAB(R) or comparable environment containing parts covered 0054 % under other licensing terms, the licensors of MATPOWER grant 0055 % you additional permission to convey the resulting work. 0056 0057 n = length(V); 0058 Ibus = Ybus * V; 0059 diaglam = sparse(1:n, 1:n, lam, n, n); 0060 diagV = sparse(1:n, 1:n, V, n, n); 0061 0062 A = sparse(1:n, 1:n, lam .* V, n, n); 0063 B = Ybus * diagV; 0064 C = A * conj(B); 0065 D = Ybus' * diagV; 0066 E = conj(diagV) * (D * diaglam - sparse(1:n, 1:n, D*lam, n, n)); 0067 F = C - A * sparse(1:n, 1:n, conj(Ibus), n, n); 0068 G = sparse(1:n, 1:n, ones(n, 1)./abs(V), n, n); 0069 0070 Gaa = E + F; 0071 Gva = 1j * G * (E - F); 0072 Gav = Gva.'; 0073 Gvv = G * (C + C.') * G;