OPF_BRANCH_ANG_FCN Evaluates branch angle difference constraints and gradients. [VADIF, DVADIF] = OPF_BRANCH_ANG_FCN(X, AANG, LANG, UANG, IANG, MPOPT); Computes the lower and upper constraints on branch angle differences for voltages in cartesian coordinates. Computes constraint vectors and their gradients. The constraints are of the form: Aang * Va >= lang Aang * Va <= uang where Va is the voltage angle, a non-linear function of the Vr and Vi. Inputs: X : optimization vector AANG : constraint matrix, see MAKEAANG LANG : lower bound vector, see MAKEAANG UANG : upper bound vector, see MAKEAANG IANG : index vector of branches corresponding to rows of AANG, LANG, UANG MPOPT : MATPOWER options struct Outputs: VADIF : constraint vector [ lang - Aang * Va; Aang * Va - uang ] DVADIF : (optional) constraint gradients Examples: VaDif = opf_branch_ang_fcn(x, Aang, lang, uang, iang, mpopt); [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang, iang, mpopt); See also OPF_BRANCH_ANG_HESS
0001 function [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang, iang, mpopt); 0002 %OPF_BRANCH_ANG_FCN Evaluates branch angle difference constraints and gradients. 0003 % [VADIF, DVADIF] = OPF_BRANCH_ANG_FCN(X, AANG, LANG, UANG, IANG, MPOPT); 0004 % 0005 % Computes the lower and upper constraints on branch angle differences 0006 % for voltages in cartesian coordinates. Computes constraint vectors and 0007 % their gradients. The constraints are of the form: 0008 % Aang * Va >= lang 0009 % Aang * Va <= uang 0010 % where Va is the voltage angle, a non-linear function of the Vr and Vi. 0011 % 0012 % Inputs: 0013 % X : optimization vector 0014 % AANG : constraint matrix, see MAKEAANG 0015 % LANG : lower bound vector, see MAKEAANG 0016 % UANG : upper bound vector, see MAKEAANG 0017 % IANG : index vector of branches corresponding to rows of AANG, LANG, UANG 0018 % MPOPT : MATPOWER options struct 0019 % 0020 % Outputs: 0021 % VADIF : constraint vector [ lang - Aang * Va; Aang * Va - uang ] 0022 % DVADIF : (optional) constraint gradients 0023 % 0024 % Examples: 0025 % VaDif = opf_branch_ang_fcn(x, Aang, lang, uang, iang, mpopt); 0026 % [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang, iang, mpopt); 0027 % 0028 % See also OPF_BRANCH_ANG_HESS 0029 0030 % MATPOWER 0031 % Copyright (c) 2018, Power Systems Engineering Research Center (PSERC) 0032 % by Baljinnyam Sereeter, Delft University of Technology 0033 % and Ray Zimmerman, PSERC Cornell 0034 % 0035 % This file is part of MATPOWER. 0036 % Covered by the 3-clause BSD License (see LICENSE file for details). 0037 % See https://matpower.org for more info. 0038 0039 %% unpack data 0040 [Vr, Vi] = deal(x{:}); 0041 0042 %% problem dimensions 0043 nb = length(Vi); %% number of buses 0044 0045 %% compute branch angle difference 0046 Va = angle(Vr + 1j* Vi); 0047 Ax = Aang * Va; 0048 VaDif = [ lang - Ax; 0049 Ax - uang ]; 0050 0051 if nargout > 1 0052 %% compute partials of branch angle difference w.r.t Vr and Vi 0053 Vm2 = Vr.^2 + Vi.^2; 0054 AangdVa_dVr = Aang * sparse(1:nb, 1:nb, -Vi./Vm2, nb, nb); 0055 AangdVa_dVi = Aang * sparse(1:nb, 1:nb, Vr./Vm2, nb, nb); 0056 dVaDif = [ -AangdVa_dVr -AangdVa_dVi; %% VaDif w.r.t Vr, Vi 0057 AangdVa_dVr AangdVa_dVi ]; 0058 end