DABR_DV Partial derivatives of squared flow magnitudes w.r.t voltage. [DAF_DVA, DAF_DVM, DAT_DVA, DAT_DVM] = ... DABR_DV(DFF_DVA, DFF_DVM, DFT_DVA, DFT_DVM, FF, FT) returns four matrices containing partial derivatives of the square of the branch flow magnitudes at "from" & "to" ends of each branch w.r.t voltage magnitude and voltage angle respectively (for all buses), given the flows and flow sensitivities. Flows could be complex current or complex or real power. Notation below is based on complex power. The following explains the expressions used to form the matrices: Let Af refer to the square of the apparent power at the "from" end of each branch, Af = abs(Sf).^2 = Sf .* conj(Sf) = Pf.^2 + Qf.^2 then ... Partial w.r.t real power, dAf/dPf = 2 * diag(Pf) Partial w.r.t reactive power, dAf/dQf = 2 * diag(Qf) Partial w.r.t Vm & Va dAf/dVm = dAf/dPf * dPf/dVm + dAf/dQf * dQf/dVm dAf/dVa = dAf/dPf * dPf/dVa + dAf/dQf * dQf/dVa Derivations for "to" bus are similar. Examples: %% squared current magnitude [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... dIbr_dV(branch(il,:), Yf, Yt, V); [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); %% squared apparent power flow [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... dSbr_dV(branch(il,:), Yf, Yt, V); [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); %% squared real power flow [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... dSbr_dV(branch(il,:), Yf, Yt, V); dFf_dVa = real(dFf_dVa); dFf_dVm = real(dFf_dVm); dFt_dVa = real(dFt_dVa); dFt_dVm = real(dFt_dVm); [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); See also DIBR_DV, 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 [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... 0002 dAbr_dV(dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St) 0003 %DABR_DV Partial derivatives of squared flow magnitudes w.r.t voltage. 0004 % [DAF_DVA, DAF_DVM, DAT_DVA, DAT_DVM] = ... 0005 % DABR_DV(DFF_DVA, DFF_DVM, DFT_DVA, DFT_DVM, FF, FT) 0006 % returns four matrices containing partial derivatives of the square of 0007 % the branch flow magnitudes at "from" & "to" ends of each branch w.r.t 0008 % voltage magnitude and voltage angle respectively (for all buses), given 0009 % the flows and flow sensitivities. Flows could be complex current or 0010 % complex or real power. Notation below is based on complex power. The 0011 % following explains the expressions used to form the matrices: 0012 % 0013 % Let Af refer to the square of the apparent power at the "from" end of 0014 % each branch, 0015 % 0016 % Af = abs(Sf).^2 0017 % = Sf .* conj(Sf) 0018 % = Pf.^2 + Qf.^2 0019 % 0020 % then ... 0021 % 0022 % Partial w.r.t real power, 0023 % dAf/dPf = 2 * diag(Pf) 0024 % 0025 % Partial w.r.t reactive power, 0026 % dAf/dQf = 2 * diag(Qf) 0027 % 0028 % Partial w.r.t Vm & Va 0029 % dAf/dVm = dAf/dPf * dPf/dVm + dAf/dQf * dQf/dVm 0030 % dAf/dVa = dAf/dPf * dPf/dVa + dAf/dQf * dQf/dVa 0031 % 0032 % Derivations for "to" bus are similar. 0033 % 0034 % Examples: 0035 % %% squared current magnitude 0036 % [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... 0037 % dIbr_dV(branch(il,:), Yf, Yt, V); 0038 % [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... 0039 % dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); 0040 % 0041 % %% squared apparent power flow 0042 % [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... 0043 % dSbr_dV(branch(il,:), Yf, Yt, V); 0044 % [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... 0045 % dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); 0046 % 0047 % %% squared real power flow 0048 % [dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft] = ... 0049 % dSbr_dV(branch(il,:), Yf, Yt, V); 0050 % dFf_dVa = real(dFf_dVa); 0051 % dFf_dVm = real(dFf_dVm); 0052 % dFt_dVa = real(dFt_dVa); 0053 % dFt_dVm = real(dFt_dVm); 0054 % [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ... 0055 % dAbr_dV(dFf_dVa, dFf_dVm, dFt_dVa, dFt_dVm, Ff, Ft); 0056 % 0057 % See also DIBR_DV, DSBR_DV. 0058 % 0059 % For more details on the derivations behind the derivative code used 0060 % in MATPOWER information, see: 0061 % 0062 % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 0063 % their Derivatives using Complex Matrix Notation", MATPOWER 0064 % Technical Note 2, February 2010. 0065 % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 0066 0067 % MATPOWER 0068 % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 0069 % by Ray Zimmerman, PSERC Cornell 0070 % 0071 % $Id: dAbr_dV.m 2644 2015-03-11 19:34:22Z ray $ 0072 % 0073 % This file is part of MATPOWER. 0074 % Covered by the 3-clause BSD License (see LICENSE file for details). 0075 % See http://www.pserc.cornell.edu/matpower/ for more info. 0076 0077 %% dimensions 0078 nl = length(Sf); 0079 0080 %%----- partials w.r.t. real and reactive power flows ----- 0081 dAf_dPf = sparse(1:nl, 1:nl, 2 * real(Sf), nl, nl); 0082 dAf_dQf = sparse(1:nl, 1:nl, 2 * imag(Sf), nl, nl); 0083 dAt_dPt = sparse(1:nl, 1:nl, 2 * real(St), nl, nl); 0084 dAt_dQt = sparse(1:nl, 1:nl, 2 * imag(St), nl, nl); 0085 0086 %% partials w.r.t. voltage magnitudes and angles 0087 dAf_dVm = dAf_dPf * real(dSf_dVm) + dAf_dQf * imag(dSf_dVm); 0088 dAf_dVa = dAf_dPf * real(dSf_dVa) + dAf_dQf * imag(dSf_dVa); 0089 dAt_dVm = dAt_dPt * real(dSt_dVm) + dAt_dQt * imag(dSt_dVm); 0090 dAt_dVa = dAt_dPt * real(dSt_dVa) + dAt_dQt * imag(dSt_dVa);