OPF_BRANCH_ANG_FCN Evaluates branch angle difference constraints and gradients. [VADIF, DVADIF] = OPF_BRANCH_ANG_FCN(X, AANG, LANG, UANG); 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 Outputs: VADIF : constraint vector [ lang - Aang * Va; Aang * Va - uang ] DVADIF : (optional) constraint gradients Examples: VaDif = opf_branch_ang_fcn(x, Aang, lang, uang); [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang); See also OPF_BRANCH_ANG_HESS
0001 function [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang); 0002 %OPF_BRANCH_ANG_FCN Evaluates branch angle difference constraints and gradients. 0003 % [VADIF, DVADIF] = OPF_BRANCH_ANG_FCN(X, AANG, LANG, UANG); 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 % 0018 % Outputs: 0019 % VADIF : constraint vector [ lang - Aang * Va; Aang * Va - uang ] 0020 % DVADIF : (optional) constraint gradients 0021 % 0022 % Examples: 0023 % VaDif = opf_branch_ang_fcn(x, Aang, lang, uang); 0024 % [VaDif, dVaDif] = opf_branch_ang_fcn(x, Aang, lang, uang); 0025 % 0026 % See also OPF_BRANCH_ANG_HESS 0027 0028 % MATPOWER 0029 % Copyright (c) 2018-2020, Power Systems Engineering Research Center (PSERC) 0030 % by Baljinnyam Sereeter, Delft University of Technology 0031 % and Ray Zimmerman, PSERC Cornell 0032 % 0033 % This file is part of MATPOWER. 0034 % Covered by the 3-clause BSD License (see LICENSE file for details). 0035 % See https://matpower.org for more info. 0036 0037 %% unpack data 0038 [Vr, Vi] = deal(x{:}); 0039 0040 %% problem dimensions 0041 nb = length(Vi); %% number of buses 0042 0043 %% compute branch angle difference 0044 Va = angle(Vr + 1j* Vi); 0045 Ax = Aang * Va; 0046 VaDif = [ lang - Ax; 0047 Ax - uang ]; 0048 0049 if nargout > 1 0050 %% compute partials of branch angle difference w.r.t Vr and Vi 0051 Vm2 = Vr.^2 + Vi.^2; 0052 AangdVa_dVr = Aang * sparse(1:nb, 1:nb, -Vi./Vm2, nb, nb); 0053 AangdVa_dVi = Aang * sparse(1:nb, 1:nb, Vr./Vm2, nb, nb); 0054 dVaDif = [ -AangdVa_dVr -AangdVa_dVi; %% VaDif w.r.t Vr, Vi 0055 AangdVa_dVr AangdVa_dVi ]; 0056 end