D2IBR_DV2 Computes 2nd derivatives of complex branch current w.r.t. voltage. [HAA, HAV, HVA, HVV] = D2IBR_DV2(CBR, YBR, 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 branch currents. Takes sparse branch admittance matrix YBR, voltage vector V and nl x 1 vector of multipliers LAM. Output matrices are sparse. Example: [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); Ybr = Yf; [Haa, Hav, Hva, Hvv] = d2Ibr_dV2(Ybr, V, lam); Here the output matrices correspond to: Haa = (d/dVa (dIbr_dVa.')) * lam Hav = (d/dVm (dIbr_dVa.')) * lam Hva = (d/dVa (dIbr_dVm.')) * lam Hvv = (d/dVm (dIbr_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 [Haa, Hav, Hva, Hvv] = d2Ibr_dV2(Ybr, V, lam) 0002 %D2IBR_DV2 Computes 2nd derivatives of complex branch current w.r.t. voltage. 0003 % [HAA, HAV, HVA, HVV] = D2IBR_DV2(CBR, YBR, 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 branch currents. Takes sparse branch admittance matrix YBR, 0007 % voltage vector V and nl x 1 vector of multipliers LAM. Output matrices 0008 % are sparse. 0009 % 0010 % Example: 0011 % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 0012 % Ybr = Yf; 0013 % [Haa, Hav, Hva, Hvv] = d2Ibr_dV2(Ybr, V, lam); 0014 % 0015 % Here the output matrices correspond to: 0016 % Haa = (d/dVa (dIbr_dVa.')) * lam 0017 % Hav = (d/dVm (dIbr_dVa.')) * lam 0018 % Hva = (d/dVa (dIbr_dVm.')) * lam 0019 % Hvv = (d/dVm (dIbr_dVm.')) * lam 0020 % 0021 % For more details on the derivations behind the derivative code used 0022 % in MATPOWER information, see: 0023 % 0024 % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 0025 % their Derivatives using Complex Matrix Notation", MATPOWER 0026 % Technical Note 2, February 2010. 0027 % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 0028 0029 % MATPOWER 0030 % $Id: d2Ibr_dV2.m 1720 2010-11-16 16:05:47Z cvs $ 0031 % by Ray Zimmerman, PSERC Cornell 0032 % Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC) 0033 % 0034 % This file is part of MATPOWER. 0035 % See http://www.pserc.cornell.edu/matpower/ for more info. 0036 % 0037 % MATPOWER is free software: you can redistribute it and/or modify 0038 % it under the terms of the GNU General Public License as published 0039 % by the Free Software Foundation, either version 3 of the License, 0040 % or (at your option) any later version. 0041 % 0042 % MATPOWER is distributed in the hope that it will be useful, 0043 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0044 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0045 % GNU General Public License for more details. 0046 % 0047 % You should have received a copy of the GNU General Public License 0048 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0049 % 0050 % Additional permission under GNU GPL version 3 section 7 0051 % 0052 % If you modify MATPOWER, or any covered work, to interface with 0053 % other modules (such as MATLAB code and MEX-files) available in a 0054 % MATLAB(R) or comparable environment containing parts covered 0055 % under other licensing terms, the licensors of MATPOWER grant 0056 % you additional permission to convey the resulting work. 0057 0058 %% define 0059 nb = length(V); 0060 0061 diaginvVm = sparse(1:nb, 1:nb, ones(nb, 1)./abs(V), nb, nb); 0062 0063 Haa = sparse(1:nb, 1:nb, -(Ybr.' * lam) .* V, nb, nb); 0064 Hva = -1j * Haa * diaginvVm; 0065 Hav = Hva; 0066 Hvv = sparse(nb, nb);