Home > matpower4.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 %   $Id: polycost.m,v 1.5 2010/04/26 19:45:25 ray Exp $
0019 %   by Ray Zimmerman, PSERC Cornell
0020 %   Copyright (c) 2009-2010 by Power System Engineering Research Center (PSERC)
0021 %
0022 %   This file is part of MATPOWER.
0023 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0024 %
0025 %   MATPOWER is free software: you can redistribute it and/or modify
0026 %   it under the terms of the GNU General Public License as published
0027 %   by the Free Software Foundation, either version 3 of the License,
0028 %   or (at your option) any later version.
0029 %
0030 %   MATPOWER is distributed in the hope that it will be useful,
0031 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0032 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0033 %   GNU General Public License for more details.
0034 %
0035 %   You should have received a copy of the GNU General Public License
0036 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0037 %
0038 %   Additional permission under GNU GPL version 3 section 7
0039 %
0040 %   If you modify MATPOWER, or any covered work, to interface with
0041 %   other modules (such as MATLAB code and MEX-files) available in a
0042 %   MATLAB(R) or comparable environment containing parts covered
0043 %   under other licensing terms, the licensors of MATPOWER grant
0044 %   you additional permission to convey the resulting work.
0045 
0046 %%----- initialize -----
0047 %% define named indices into data matrices
0048 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0049 
0050 if nargin < 3
0051     der = 0;
0052 end
0053 
0054 if any(gencost(:, MODEL) == PW_LINEAR)
0055     error('polycost: all costs must be polynomial');
0056 end
0057 
0058 ng = length(Pg);
0059 maxN = max(gencost(:, NCOST));
0060 minN = min(gencost(:, NCOST));
0061 
0062 %% form coefficient matrix where 1st column is constant term, 2nd linear, etc.
0063 c = zeros(ng, maxN);
0064 for n = minN:maxN
0065     k = find(gencost(:, NCOST) == n);   %% cost with n coefficients
0066     c(k, 1:n) = gencost(k, (COST+n-1):-1:COST);
0067 end
0068 
0069 %% do derivatives
0070 for d = 1:der
0071     if size(c, 2) >= 2
0072         c = c(:, 2:maxN-d+1);
0073     else
0074         c = zeros(ng, 1);
0075         break;
0076     end
0077     for k = 2:maxN-d
0078         c(:, k) = k * c(:, k);
0079     end
0080 end
0081 
0082 %% evaluate polynomial
0083 if isempty(c)
0084     f = zeros(size(Pg));
0085 else
0086     f = c(:, 1);        %% constant term
0087     for k = 2:size(c, 2)
0088         f = f + c(:, k) .* Pg .^ (k-1);
0089     end
0090 end

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005