Home > matpower5.1 > 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
   NPTS evenly spaced points between PMIN and PMAX. If the range does not
   include 0, then it is evaluated at 0 and NPTS-1 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 %   NPTS evenly spaced points between PMIN and PMAX. If the range does not
0006 %   include 0, then it is evaluated at 0 and NPTS-1 evenly spaced points
0007 %   between PMIN and PMAX.
0008 
0009 %   MATPOWER
0010 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0011 %   by Ray Zimmerman, PSERC Cornell
0012 %
0013 %   $Id: poly2pwl.m 2644 2015-03-11 19:34:22Z ray $
0014 %
0015 %   This file is part of MATPOWER.
0016 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0017 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0018 
0019 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0020 
0021 pwlcost = polycost;
0022 [m, n] = size(polycost);            %% size of piece being changed
0023 pwlcost(:, MODEL)  = PW_LINEAR;     %% change cost model
0024 pwlcost(:, COST:n) = 0;             %% zero out old data
0025 pwlcost(:, NCOST)  = npts;          %% change number of data points
0026 pwlcost(1, COST+2*(npts-1)+1) = 0;  %% expand as needed
0027 
0028 for i = 1:m
0029     if Pmin(i) > 0
0030         step = (Pmax(i) - Pmin(i)) / (npts - 2);
0031         xx = [0 Pmin(i):step:Pmax(i)];
0032     elseif Pmax(i) < 0
0033         step = (Pmax(i) - Pmin(i)) / (npts - 2);
0034         xx = [Pmin(i):step:Pmax(i) 0];
0035     else
0036         step = (Pmax(i) - Pmin(i)) / (npts - 1);
0037         xx = (Pmin(i):step:Pmax(i));
0038     end
0039     yy = totcost(polycost(i, :), xx);
0040     pwlcost(i,      COST:2:(COST + 2*(npts-1)    )) = xx;
0041     pwlcost(i,  (COST+1):2:(COST + 2*(npts-1) + 1)) = yy;
0042 end

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