OPF_VEQ_FCN Evaluates voltage magnitude equality constraint and gradients. [Veq, dVeq] = OPF_VEQ_FCN(X, MPC, IDX, MPOPT) Computes the voltage magnitudes using real and imaginary part of complex voltage for AC optimal power flow. Computes constraint vectors and their gradients. Inputs: X : optimization vector MPC : MATPOWER case struct IDX : index of buses whose voltage magnitudes should be fixed MPOPT : MATPOWER options struct Outputs: VEQ : vector of voltage magnitudes DVEQ : (optional) magnitude gradients Examples: Veq = opf_veq_fcn(x, mpc, mpopt); [Veq, dVeq] = opf_veq_fcn(x, mpc, idx, mpopt); See also OPF_VEQ_HESS
0001 function [Veq, dVeq] = opf_veq_fcn(x, mpc, idx, mpopt) 0002 %OPF_VEQ_FCN Evaluates voltage magnitude equality constraint and gradients. 0003 % [Veq, dVeq] = OPF_VEQ_FCN(X, MPC, IDX, MPOPT) 0004 % 0005 % Computes the voltage magnitudes using real and imaginary part of complex voltage for 0006 % AC optimal power flow. Computes constraint vectors and their gradients. 0007 % 0008 % Inputs: 0009 % X : optimization vector 0010 % MPC : MATPOWER case struct 0011 % IDX : index of buses whose voltage magnitudes should be fixed 0012 % MPOPT : MATPOWER options struct 0013 % 0014 % Outputs: 0015 % VEQ : vector of voltage magnitudes 0016 % DVEQ : (optional) magnitude gradients 0017 % 0018 % Examples: 0019 % Veq = opf_veq_fcn(x, mpc, mpopt); 0020 % [Veq, dVeq] = opf_veq_fcn(x, mpc, idx, mpopt); 0021 % 0022 % See also OPF_VEQ_HESS 0023 0024 % MATPOWER 0025 % Copyright (c) 2018, Power Systems Engineering Research Center (PSERC) 0026 % by Ray Zimmerman, PSERC Cornell 0027 % and Baljinnyam Sereeter, Delft University of Technology 0028 % 0029 % This file is part of MATPOWER. 0030 % Covered by the 3-clause BSD License (see LICENSE file for details). 0031 % See https://matpower.org for more info. 0032 0033 %% define named indices into data matrices 0034 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0035 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0036 0037 %% unpack data 0038 [Vr, Vi] = deal(x{:}); 0039 0040 %% problem dimensions 0041 nb = length(Vi); %% number of buses 0042 n = length(idx); %% number of buses with fixed voltage magnitudes 0043 0044 %% compute voltage magnitude 0045 Vm2 = Vr(idx).^2 + Vi(idx).^2; 0046 Veq = Vm2 - mpc.bus(idx, VMAX).^2; 0047 0048 if nargout > 1 0049 %% compute partials of voltage magnitude w.r.t Vr and Vi 0050 dVm_dVr = sparse(1:n, idx, 2 * Vr(idx), n, nb); 0051 dVm_dVi = sparse(1:n, idx, 2 * Vi(idx), n, nb); 0052 dVeq = [ dVm_dVr dVm_dVi ]; %% Vm2 w.r.t Vr, Vi 0053 end