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.
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-2015 by Power System Engineering Research Center (PSERC) 0011 % by Ray Zimmerman, PSERC Cornell 0012 % & Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 0013 % 0014 % $Id: margcost.m 2644 2015-03-11 19:34:22Z ray $ 0015 % 0016 % This file is part of MATPOWER. 0017 % Covered by the 3-clause BSD License (see LICENSE file for details). 0018 % See http://www.pserc.cornell.edu/matpower/ for more info. 0019 0020 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 0021 0022 [ng, m] = size(gencost); 0023 marginalcost = zeros(ng, 1); 0024 0025 if ~isempty(gencost) 0026 ipwl = find(gencost(:, MODEL) == PW_LINEAR); 0027 ipol = find(gencost(:, MODEL) == POLYNOMIAL); 0028 if ~isempty(ipwl) 0029 x = gencost(:, COST:2:(m-1)); 0030 y = gencost(:, (COST+1):2:m); 0031 for i = ipwl' 0032 if gencost(i, NCOST) > 0 0033 c = diff(y(i,:)) ./ diff(x(i,:)); 0034 k = find(Pg(i,:) <= x(i,:), 1); 0035 if isempty(k) 0036 marginalcost(i,:) = c(end); 0037 elseif k == 1 0038 marginalcost(i,:) = c(1); 0039 else 0040 marginalcost(i,:) = c(k-1); 0041 end 0042 end 0043 end 0044 end 0045 for i = ipol' 0046 marginalcost(i,:) = polyval(polyder(gencost(i, COST:(COST+gencost(i, NCOST)-1) )), Pg(i,:) ); 0047 end 0048 end