gusucode.com > matpower工具箱源码程序 > matpower工具箱源码程序/MP2_0/poly2pwl.m
function pwlcost = poly2pwl(polycost, Pmin, Pmax, npts) %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. % MATPOWER Version 2.0 % by Ray Zimmerman, PSERC Cornell 9/19/97 % Copyright (c) 1997 by Power System Engineering Research Center (PSERC) % See http://www.pserc.cornell.edu/ for more info. [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, N, COST] = idx_cost; pwlcost = polycost; [m, n] = size(polycost); %% size of piece being changed pwlcost(:, MODEL) = PW_LINEAR * ones(m, 1); %% change cost model pwlcost(:, COST:n) = zeros(size(pwlcost(:, COST:n))); %% zero out old data pwlcost(:, N) = npts * ones(m, 1); %% change number of data points for i = 1:m if Pmin(i) == 0 step = (Pmax(i) - Pmin(i)) / (npts - 1); xx = [Pmin(i):step:Pmax(i)]; elseif Pmin(i) > 0 step = (Pmax(i) - Pmin(i)) / (npts - 2); xx = [0 Pmin(i):step:Pmax(i)]; elseif Pmin(i) < 0 & Pmax(i) > 0 %% for when P really means Q step = (Pmax(i) - Pmin(i)) / (npts - 1); xx = [Pmin(i):step:Pmax(i)]; end yy = totcost(polycost(i, :), xx); pwlcost(i, COST:2:(COST + 2*(npts-1) )) = xx; pwlcost(i, (COST+1):2:(COST + 2*(npts-1) + 1)) = yy; end return;