📄 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% $Id: poly2pwl.m,v 1.4 2004/08/23 20:56:53 ray Exp $% by Ray Zimmerman, PSERC Cornell% Copyright (c) 1996-2004 by Power System Engineering Research Center (PSERC)% See http://www.pserc.cornell.edu/matpower/ for more info.[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, N, COST] = idx_cost;pwlcost = polycost;[m, n] = size(polycost); %% size of piece being changedpwlcost(:, MODEL) = PW_LINEAR * ones(m, 1); %% change cost modelpwlcost(:, COST:n) = zeros(size(pwlcost(:, COST:n))); %% zero out old datapwlcost(:, N) = npts * ones(m, 1); %% change number of data pointsfor 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;endreturn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -