how can I model contains summation of different sdpvar inside a "FOR loop"

45 views
Skip to first unread message

Ahmed Rabee

unread,
Nov 8, 2017, 9:21:38 AM11/8/17
to YALMIP

I want to model this equation:

for t = 1:24, for n=1:5,  Do    
       Sum[ FP (k,t) ] + P(n,t) = L(n,t)   where, k selected from K =[ 1:6 ] based on n  

and
FP  is Linear matrix variable 6x24 (full, real, 120 variables)
P is linear matrix variable 5x24 (full, real, 120 variables)
L is 5*24 double.

Please refer to the attached file lines 34:46, 
No error but these constraints not working !!!!

IEEE_5.m
Power_Opt.m

Johan Löfberg

unread,
Nov 8, 2017, 10:31:45 AM11/8/17
to YALMIP
WEll, thr ode is correct matlab code, so you're simply not writing the matlab code you think.

Since you only say it is incorrect but not how, it i impossible to understand what you want and what you got. There is no sum in the code though which you have in you post test

Ahmed Rabee

unread,
Nov 8, 2017, 11:54:59 AM11/8/17
to YALMIP
I use the following lines to make the summation: line 36-38

for l_n=1:length(lineNo)           % for all connected lines connected to node n
                FP_n(n,t)  = FP_n(n,t) + (-1)^dir(l_n) * FP(lineNo(l_n),t);
end
then I use the sumation in Lines 42  or 44:
                Constraints     = [Constraints, FP_n(n,t) + P(gen_index,t)  == load_n(n)] ;  
or             Constraints     = [Constraints, FP_n(n,t) == load_n(n)] ;      


where, l_n is k of the equation, lineNo is a subset of K, gen_index is n if there, Load_n is L

so we can write this loop like:
for  k =1: K_sub          % for all connected lines connected to node n
                FP_n(n,t)  = FP_n(n,t) + (-1)^dir(l_n) * FP(k,t);
end

thank you, professor, for your help

Johan Löfberg

unread,
Nov 8, 2017, 12:31:28 PM11/8/17
to YALMIP
so you've solved your problems?

this looks fishy though

FP_n  = sdpvar(N, TN, 'full');
           for l_n=1:length(lineNo)           % for all connected lines connected to node n
                FP_n(n,t)  = FP_n(n,t) + (-1)^dir(l_n) * FP(lineNo(l_n),t);
            end

as that means FP_n will be the sum of FP etc, plus the decision variable that initially was in FP_n, and since there are no constraints on those, FP_n is effectively completely free

Anology

x = sdpvar(1) % Variable 1
y = sdpvar(2,1); Variable 2 and 3
for i = 1:n
 x = x + y(i);
end

Will lead to y = variable1 + variable2 + variable3.

Reply all
Reply to author
Forward
0 new messages