D2ASBR_DV2 Computes 2nd derivatives of |complex power flow|^2 w.r.t. V. [HAA, HAV, HVA, HVV] = D2ASBR_DV2(DSBR_DVA, DSBR_DVM, SBR, 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 square of the magnitude of branch complex power flows. Takes sparse first derivative matrices of complex flow, complex flow vector, sparse connection matrix CBR, sparse branch admittance matrix YBR, voltage vector V and nl x 1 vector of multipliers LAM. Output matrices are sparse. Example: f = branch(:, F_BUS); Cf = sparse(1:nl, f, ones(nl, 1), nl, nb); [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); [dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St] = ... dSbr_dV(branch, Yf, Yt, V); Cbr = Cf; Ybr = Yf; dSbr_dVa = dSf_dVa; dSbr_dVm = dSf_dVm; Sbr = Sf; [Haa, Hav, Hva, Hvv] = ... d2ASbr_dV2(dSbr_dVa, dSbr_dVm, Sbr, Cbr, Ybr, V, lam); Here the output matrices correspond to: Haa = (d/dVa (dASbr_dVa.')) * lam Hav = (d/dVm (dASbr_dVa.')) * lam Hva = (d/dVa (dASbr_dVm.')) * lam Hvv = (d/dVm (dASbr_dVm.')) * lam See also DSBR_DV. 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] = ... 0002 d2ASbr_dV2(dSbr_dVa, dSbr_dVm, Sbr, Cbr, Ybr, V, lam) 0003 %D2ASBR_DV2 Computes 2nd derivatives of |complex power flow|^2 w.r.t. V. 0004 % [HAA, HAV, HVA, HVV] = D2ASBR_DV2(DSBR_DVA, DSBR_DVM, SBR, CBR, YBR, V, LAM) 0005 % returns 4 matrices containing the partial derivatives w.r.t. voltage 0006 % angle and magnitude of the product of a vector LAM with the 1st partial 0007 % derivatives of the square of the magnitude of branch complex power flows. 0008 % Takes sparse first derivative matrices of complex flow, complex flow 0009 % vector, sparse connection matrix CBR, sparse branch admittance matrix YBR, 0010 % voltage vector V and nl x 1 vector of multipliers LAM. Output matrices 0011 % are sparse. 0012 % 0013 % Example: 0014 % f = branch(:, F_BUS); 0015 % Cf = sparse(1:nl, f, ones(nl, 1), nl, nb); 0016 % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 0017 % [dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St] = ... 0018 % dSbr_dV(branch, Yf, Yt, V); 0019 % Cbr = Cf; 0020 % Ybr = Yf; 0021 % dSbr_dVa = dSf_dVa; 0022 % dSbr_dVm = dSf_dVm; 0023 % Sbr = Sf; 0024 % [Haa, Hav, Hva, Hvv] = ... 0025 % d2ASbr_dV2(dSbr_dVa, dSbr_dVm, Sbr, Cbr, Ybr, V, lam); 0026 % 0027 % Here the output matrices correspond to: 0028 % Haa = (d/dVa (dASbr_dVa.')) * lam 0029 % Hav = (d/dVm (dASbr_dVa.')) * lam 0030 % Hva = (d/dVa (dASbr_dVm.')) * lam 0031 % Hvv = (d/dVm (dASbr_dVm.')) * lam 0032 % 0033 % See also DSBR_DV. 0034 % 0035 % For more details on the derivations behind the derivative code used 0036 % in MATPOWER information, see: 0037 % 0038 % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 0039 % their Derivatives using Complex Matrix Notation", MATPOWER 0040 % Technical Note 2, February 2010. 0041 % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 0042 0043 % MATPOWER 0044 % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 0045 % by Ray Zimmerman, PSERC Cornell 0046 % 0047 % $Id: d2ASbr_dV2.m 2644 2015-03-11 19:34:22Z ray $ 0048 % 0049 % This file is part of MATPOWER. 0050 % Covered by the 3-clause BSD License (see LICENSE file for details). 0051 % See http://www.pserc.cornell.edu/matpower/ for more info. 0052 0053 %% define 0054 nl = length(lam); 0055 0056 diaglam = sparse(1:nl, 1:nl, lam, nl, nl); 0057 diagSbr_conj = sparse(1:nl, 1:nl, conj(Sbr), nl, nl); 0058 0059 [Saa, Sav, Sva, Svv] = d2Sbr_dV2(Cbr, Ybr, V, diagSbr_conj * lam); 0060 Haa = 2 * real( Saa + dSbr_dVa.' * diaglam * conj(dSbr_dVa) ); 0061 Hva = 2 * real( Sva + dSbr_dVm.' * diaglam * conj(dSbr_dVa) ); 0062 Hav = 2 * real( Sav + dSbr_dVa.' * diaglam * conj(dSbr_dVm) ); 0063 Hvv = 2 * real( Svv + dSbr_dVm.' * diaglam * conj(dSbr_dVm) );