Home > matpower7.0 > lib > margcost.m

margcost

PURPOSE ^

MARGCOST Computes marginal cost for generators at given output level.

SYNOPSIS ^

function marginalcost = margcost(gencost, Pg)

DESCRIPTION ^

MARGCOST    Computes marginal cost for generators at given output level.
   MARGINALCOST = MARGCOST(GENCOST, PG) computes marginal cost for generators
   given a matrix in gencost format and a column vector of generation levels.
   The return value has the same dimensions as PG. Each row of GENCOST is
   used to evaluate the cost at the points specified in the corresponding row
   of PG.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function marginalcost = margcost(gencost, Pg)
0002 %MARGCOST    Computes marginal cost for generators at given output level.
0003 %   MARGINALCOST = MARGCOST(GENCOST, PG) computes marginal cost for generators
0004 %   given a matrix in gencost format and a column vector of generation levels.
0005 %   The return value has the same dimensions as PG. Each row of GENCOST is
0006 %   used to evaluate the cost at the points specified in the corresponding row
0007 %   of PG.
0008 
0009 %   MATPOWER
0010 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0011 %   by Ray Zimmerman, PSERC Cornell
0012 %   & Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Nacional de Colombia
0013 %
0014 %   This file is part of MATPOWER.
0015 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0016 %   See https://matpower.org for more info.
0017 
0018 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0019 
0020 [ng, m] = size(gencost);
0021 marginalcost = zeros(ng, 1);
0022 
0023 if ~isempty(gencost)
0024   ipwl = find(gencost(:, MODEL) == PW_LINEAR);
0025   ipol = find(gencost(:, MODEL) == POLYNOMIAL);
0026   if ~isempty(ipwl)
0027     x = gencost(:, COST:2:(m-1));
0028     y = gencost(:, (COST+1):2:m);
0029     for i = ipwl'
0030       if gencost(i, NCOST) > 0
0031         c = diff(y(i,:)) ./ diff(x(i,:));
0032         k = find(Pg(i,:) <= x(i,:), 1);
0033         if isempty(k)
0034           marginalcost(i,:) = c(end);
0035         elseif k == 1
0036           marginalcost(i,:) = c(1);
0037         else
0038           marginalcost(i,:) = c(k-1);
0039         end
0040       end
0041     end
0042   end
0043   for i = ipol'
0044     marginalcost(i,:) = polyval(polyder(gencost(i, COST:(COST+gencost(i, NCOST)-1) )), Pg(i,:) );
0045   end
0046 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005