Home > matpower5.0 > poly2pwl.m

poly2pwl

PURPOSE ^

POLY2PWL Converts polynomial cost variable to piecewise linear.

SYNOPSIS ^

function pwlcost = poly2pwl(polycost, Pmin, Pmax, npts)

DESCRIPTION ^

POLY2PWL  Converts polynomial cost variable to piecewise linear.
   PWLCOST = POLY2PWL(POLYCOST, PMIN, PMAX, NPTS) converts the polynomial
   cost variable POLYCOST into a piece-wise linear cost by evaluating at
   zero and then at NPTS evenly spaced points between PMIN and PMAX. If
   PMIN <= 0 (such as for reactive power, where P really means Q) it just
   uses NPTS evenly spaced points between PMIN and PMAX.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pwlcost = poly2pwl(polycost, Pmin, Pmax, npts)
0002 %POLY2PWL  Converts polynomial cost variable to piecewise linear.
0003 %   PWLCOST = POLY2PWL(POLYCOST, PMIN, PMAX, NPTS) converts the polynomial
0004 %   cost variable POLYCOST into a piece-wise linear cost by evaluating at
0005 %   zero and then at NPTS evenly spaced points between PMIN and PMAX. If
0006 %   PMIN <= 0 (such as for reactive power, where P really means Q) it just
0007 %   uses NPTS evenly spaced points between PMIN and PMAX.
0008 
0009 %   MATPOWER
0010 %   $Id: poly2pwl.m 1635 2010-04-26 19:45:26Z ray $
0011 %   by Ray Zimmerman, PSERC Cornell
0012 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0013 %
0014 %   This file is part of MATPOWER.
0015 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0016 %
0017 %   MATPOWER is free software: you can redistribute it and/or modify
0018 %   it under the terms of the GNU General Public License as published
0019 %   by the Free Software Foundation, either version 3 of the License,
0020 %   or (at your option) any later version.
0021 %
0022 %   MATPOWER is distributed in the hope that it will be useful,
0023 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0025 %   GNU General Public License for more details.
0026 %
0027 %   You should have received a copy of the GNU General Public License
0028 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0029 %
0030 %   Additional permission under GNU GPL version 3 section 7
0031 %
0032 %   If you modify MATPOWER, or any covered work, to interface with
0033 %   other modules (such as MATLAB code and MEX-files) available in a
0034 %   MATLAB(R) or comparable environment containing parts covered
0035 %   under other licensing terms, the licensors of MATPOWER grant
0036 %   you additional permission to convey the resulting work.
0037 
0038 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0039 
0040 pwlcost = polycost;
0041 [m, n] = size(polycost);                                %% size of piece being changed
0042 pwlcost(:, MODEL)  = PW_LINEAR * ones(m, 1);            %% change cost model
0043 pwlcost(:, COST:n) = zeros(size(pwlcost(:, COST:n)));   %% zero out old data
0044 pwlcost(:, NCOST)  = npts * ones(m, 1);                 %% change number of data points
0045 
0046 for i = 1:m
0047     if Pmin(i) == 0
0048         step = (Pmax(i) - Pmin(i)) / (npts - 1);
0049         xx = (Pmin(i):step:Pmax(i));
0050     elseif Pmin(i) > 0
0051         step = (Pmax(i) - Pmin(i)) / (npts - 2);
0052         xx = [0 Pmin(i):step:Pmax(i)];
0053     elseif Pmin(i) < 0 && Pmax(i) > 0        %% for when P really means Q
0054         step = (Pmax(i) - Pmin(i)) / (npts - 1);
0055         xx = (Pmin(i):step:Pmax(i));
0056     end
0057     yy = totcost(polycost(i, :), xx);
0058     pwlcost(i,      COST:2:(COST + 2*(npts-1)    )) = xx;
0059     pwlcost(i,  (COST+1):2:(COST + 2*(npts-1) + 1)) = yy;
0060 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005