poly2pwl.m
来自「以上所传的内容为电力系统比较全面的分析程序,才用的是matlab编写m的文件」· M 代码 · 共 40 行
M
40 行
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 + =
减小字号Ctrl + -
显示快捷键?