Home > matpower5.1 > polycost.m

polycost

PURPOSE ^

POLYCOST Evaluates polynomial generator cost & derivatives.

SYNOPSIS ^

function f = polycost(gencost, Pg, der)

DESCRIPTION ^

POLYCOST  Evaluates polynomial generator cost & derivatives.
   F = POLYCOST(GENCOST, PG) returns the vector of costs evaluated at PG

   DF = POLYCOST(GENCOST, PG, 1) returns the vector of first derivatives
   of costs evaluated at PG

   D2F = POLYCOST(GENCOST, PG, 2) returns the vector of second derivatives
   of costs evaluated at PG

   GENCOST must contain only polynomial costs
   PG is in MW, not p.u. (works for QG too)

   This is a more effecient implementation that what can be done with
   MATLAB's built-in POLYVAL and POLYDER functions.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = polycost(gencost, Pg, der)
0002 %POLYCOST  Evaluates polynomial generator cost & derivatives.
0003 %   F = POLYCOST(GENCOST, PG) returns the vector of costs evaluated at PG
0004 %
0005 %   DF = POLYCOST(GENCOST, PG, 1) returns the vector of first derivatives
0006 %   of costs evaluated at PG
0007 %
0008 %   D2F = POLYCOST(GENCOST, PG, 2) returns the vector of second derivatives
0009 %   of costs evaluated at PG
0010 %
0011 %   GENCOST must contain only polynomial costs
0012 %   PG is in MW, not p.u. (works for QG too)
0013 %
0014 %   This is a more effecient implementation that what can be done with
0015 %   MATLAB's built-in POLYVAL and POLYDER functions.
0016 
0017 %   MATPOWER
0018 %   Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC)
0019 %   by Ray Zimmerman, PSERC Cornell
0020 %
0021 %   $Id: polycost.m 2644 2015-03-11 19:34:22Z ray $
0022 %
0023 %   This file is part of MATPOWER.
0024 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0025 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0026 
0027 %%----- initialize -----
0028 %% define named indices into data matrices
0029 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0030 
0031 if nargin < 3
0032     der = 0;
0033 end
0034 
0035 if any(gencost(:, MODEL) == PW_LINEAR)
0036     error('polycost: all costs must be polynomial');
0037 end
0038 
0039 ng = length(Pg);
0040 maxN = max(gencost(:, NCOST));
0041 minN = min(gencost(:, NCOST));
0042 
0043 %% form coefficient matrix where 1st column is constant term, 2nd linear, etc.
0044 c = zeros(ng, maxN);
0045 for n = minN:maxN
0046     k = find(gencost(:, NCOST) == n);   %% cost with n coefficients
0047     c(k, 1:n) = gencost(k, (COST+n-1):-1:COST);
0048 end
0049 
0050 %% do derivatives
0051 for d = 1:der
0052     if size(c, 2) >= 2
0053         c = c(:, 2:maxN-d+1);
0054     else
0055         c = zeros(ng, 1);
0056         break;
0057     end
0058     for k = 2:maxN-d
0059         c(:, k) = k * c(:, k);
0060     end
0061 end
0062 
0063 %% evaluate polynomial
0064 if isempty(c)
0065     f = zeros(size(Pg));
0066 else
0067     f = c(:, 1);        %% constant term
0068     for k = 2:size(c, 2)
0069         f = f + c(:, k) .* Pg .^ (k-1);
0070     end
0071 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005