Dear Professor Zimmerman and all members

I still have problems with the "User-defined Cost" function in MATPOWER. In
the end I always got a convergence problem.

First, I want understand the meaning of the all variables. In the equation
(5.27) of the manual, the first term is for the quadratic part, and the
second one is for the lineal part, I am right?

For this reason if H is a zero matrix, the first term is not included in the
function. Like is in the test files in the folder t/t_opf_mips.m.

What I want to do is implement only  the quadratic part of the function,
applied to all the generators in the system.

I will need just to set N, rhat, d=2, k=0, m=0 and H.

H defined as symmetric matrix with dimension nw x nw. If I want to use all
the generators, then nw = ng, and I can define H as:

H = 2 * sparse( 1:ng,1:ng, ones(1,ng), ng, ng);

I will enclose the rest of the code to be more understandable.

Thanks,

Alvaro Jaramillo Duque

% matpower must be in the path
casefile = 'case30.m';
mpc = loadcase(casefile);

%% data dimensions
nb   = size(mpc.bus, 1);    %% number of buses
na   = max(mpc.bus(:,7));    %% number of areas
nl   = size(mpc.branch, 1); %% number of branches
ng   = size(mpc.gen, 1);    %% number of dispatchable injections

% minimizing losses in the system
% p_0 f_0  ... p_n f_n
mpc.gencost = ones(ng,1)* [1, 0, 0, 2, 0, 100, 10000, 200];

mpc_losses = runopf(mpc);
%[baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] =
runopf(mpc);

A = sparse(0,0);
l = [];
u = [];

% positions of x = [theta |V| Pg Qg]'
thbas = 1;                thend    = thbas+nb-1; % theta
vbas     = thend+1;       vend     = vbas+nb-1;  % |V|
pgbas    = vend+1;        pgend    = pgbas+ng-1; % Pg
qgbas    = pgend+1;       qgend    = qgbas+ng-1; % Qg
nxyz = 2*nb + 2*ng;
N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz); %
only Pg
fparm = ones(ng,1) * [ 2 0 0 0 ];
fparm(:,2) =  mpc_losses.gen(:,2); % start point, the result must be zero
[junk, ix] = sort(mpc.gen(:, 1));

H = 2 * sparse( 1:ng,1:ng, ones(1,ng), ng, ng);
Cw = zeros(ng,1);
mpc.gencost(:, 6:8) = 0; % erase the original objective function

%% run OPF with user-defined cost, quadratic term
mpopt = mpoption;
[r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);

Reply via email to