DSBUS_DV Computes partial derivatives of power injection w.r.t. voltage. [DSBUS_DVM, DSBUS_DVA] = DSBUS_DV(YBUS, V) returns two matrices containing partial derivatives of the complex bus power injections w.r.t voltage magnitude and voltage angle respectively (for all buses). If YBUS is a sparse matrix, the return values will be also. The following explains the expressions used to form the matrices: S = diag(V) * conj(Ibus) = diag(conj(Ibus)) * V Partials of V & Ibus w.r.t. voltage magnitudes dV/dVm = diag(V./abs(V)) dI/dVm = Ybus * dV/dVm = Ybus * diag(V./abs(V)) Partials of V & Ibus w.r.t. voltage angles dV/dVa = j * diag(V) dI/dVa = Ybus * dV/dVa = Ybus * j * diag(V) Partials of S w.r.t. voltage magnitudes dS/dVm = diag(V) * conj(dI/dVm) + diag(conj(Ibus)) * dV/dVm = diag(V) * conj(Ybus * diag(V./abs(V))) + conj(diag(Ibus)) * diag(V./abs(V)) Partials of S w.r.t. voltage angles dS/dVa = diag(V) * conj(dI/dVa) + diag(conj(Ibus)) * dV/dVa = diag(V) * conj(Ybus * j * diag(V)) + conj(diag(Ibus)) * j * diag(V) = -j * diag(V) * conj(Ybus * diag(V)) + conj(diag(Ibus)) * j * diag(V) = j * diag(V) * conj(diag(Ibus) - Ybus * diag(V)) Example: [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V); 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 [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V) 0002 %DSBUS_DV Computes partial derivatives of power injection w.r.t. voltage. 0003 % [DSBUS_DVM, DSBUS_DVA] = DSBUS_DV(YBUS, V) returns two matrices containing 0004 % partial derivatives of the complex bus power injections w.r.t voltage 0005 % magnitude and voltage angle respectively (for all buses). If YBUS is a 0006 % sparse matrix, the return values will be also. The following explains 0007 % the expressions used to form the matrices: 0008 % 0009 % S = diag(V) * conj(Ibus) = diag(conj(Ibus)) * V 0010 % 0011 % Partials of V & Ibus w.r.t. voltage magnitudes 0012 % dV/dVm = diag(V./abs(V)) 0013 % dI/dVm = Ybus * dV/dVm = Ybus * diag(V./abs(V)) 0014 % 0015 % Partials of V & Ibus w.r.t. voltage angles 0016 % dV/dVa = j * diag(V) 0017 % dI/dVa = Ybus * dV/dVa = Ybus * j * diag(V) 0018 % 0019 % Partials of S w.r.t. voltage magnitudes 0020 % dS/dVm = diag(V) * conj(dI/dVm) + diag(conj(Ibus)) * dV/dVm 0021 % = diag(V) * conj(Ybus * diag(V./abs(V))) 0022 % + conj(diag(Ibus)) * diag(V./abs(V)) 0023 % 0024 % Partials of S w.r.t. voltage angles 0025 % dS/dVa = diag(V) * conj(dI/dVa) + diag(conj(Ibus)) * dV/dVa 0026 % = diag(V) * conj(Ybus * j * diag(V)) 0027 % + conj(diag(Ibus)) * j * diag(V) 0028 % = -j * diag(V) * conj(Ybus * diag(V)) 0029 % + conj(diag(Ibus)) * j * diag(V) 0030 % = j * diag(V) * conj(diag(Ibus) - Ybus * diag(V)) 0031 % 0032 % Example: 0033 % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 0034 % [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V); 0035 % 0036 % For more details on the derivations behind the derivative code used 0037 % in MATPOWER information, see: 0038 % 0039 % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 0040 % their Derivatives using Complex Matrix Notation", MATPOWER 0041 % Technical Note 2, February 2010. 0042 % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 0043 0044 % MATPOWER 0045 % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 0046 % by Ray Zimmerman, PSERC Cornell 0047 % 0048 % $Id: dSbus_dV.m 2644 2015-03-11 19:34:22Z ray $ 0049 % 0050 % This file is part of MATPOWER. 0051 % Covered by the 3-clause BSD License (see LICENSE file for details). 0052 % See http://www.pserc.cornell.edu/matpower/ for more info. 0053 0054 n = length(V); 0055 Ibus = Ybus * V; 0056 0057 if issparse(Ybus) %% sparse version (if Ybus is sparse) 0058 diagV = sparse(1:n, 1:n, V, n, n); 0059 diagIbus = sparse(1:n, 1:n, Ibus, n, n); 0060 diagVnorm = sparse(1:n, 1:n, V./abs(V), n, n); 0061 else %% dense version 0062 diagV = diag(V); 0063 diagIbus = diag(Ibus); 0064 diagVnorm = diag(V./abs(V)); 0065 end 0066 0067 dSbus_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm; 0068 dSbus_dVa = 1j * diagV * conj(diagIbus - Ybus * diagV);