SOC constrain can I apply it without for loop


(EHTISHAM ASGHAR) #1
% Curtailed inclusion   
cvx_clear
%input data
alpha1 = 2; beta1 = 3;
alpha2 = 4; beta2 = 5;
alpha3 = 6; beta3 = 7;
cl = 5;   bat = 1.5;
D = [5 3 7 2 12 20 6 9 5 7 11 12 11 10 5 6 7 4 9 7 9 10 7 5];
u = [1 1 2 2 300 100 4 4 5 5 2 100 1 7 7 5 5 3 3 0 0 1 1 8];
T = 24; d = 3;    
W = [5 12 6 7 8 1 1 1 2 2 3 3 1 1 1 2 2 2 3 2 1 1 2 3];
cvx_begin
    variables p(T,d) pg(T,1) pw(T,1) pcurl(T,1) pch_dis(T,1);
    expression soc(T,1);
    soc(1) = 35;
    for t=1:T -1                                                           % (SOC Constrain) soc(t+1) = soc(t) + p(t)
        soc(t+1) = soc(t) + pch_dis(t);
    end
    
    minimize(sum(alpha1*p(:,1).^2 + beta1*p(:,1) + alpha2*p(:,2).^2 + beta2*p(:,2) + alpha3*p(:,3).^2 + beta3*p(:,3) +...
    u'.*pg + cl*pcurl.^2 + bat*pch_dis.^2));
    
    subject to
            sum(p(:,:),2)+ pg + pw - pch_dis == D' - pcurl;                       % Power balance constraint    
            0 <= p(:,1) <= 4;                                   % Dg up & down limit constraint
            0 <= p(:,2) <= 6;                                   % Dg up & down limit constraint
            0 <= p(:,3) <= 9;                                   % Dg up & down limit constraint 
            norms(p(2:T,:) - p(1:T-1,:),Inf,1) <= [3 5 8];      % ramp up & down constraint
            -4 <= pg <= 4;                                      % Grid power constriant
            0 <= pw <= W';                                      % Wind power constraint
            0 <= pcurl <= 4;                                    % Curtiled load constraint
            -10 <= pch_dis <= 10;                                  % Battery charge discharge rate
            0 <= soc <= 35;                                    % Soc constraint
    cvx_end

(Mark L. Stone) #2

Given that diff is not supported by CVX, I don’t see how to do it without a for loop. Your code seems to work (I have no idea what it’s supposed to be doing though), even though you declared SOC as having T elements, but set soc(T+1).

By the way, when people around “here” see SOC constraint, they probably think it is Second Order Cone constraint.


(EHTISHAM ASGHAR) #3

yes sir mark I have set to T-1 in the loop you are right, by this for loop I want to implement that state of charge(SOC) of battery in the next time period should be equal SOC in previous time period + charging discharging power in previous time period.

SOC(t+1) = SOC(t) + Pcha_disch(t)