Hello, from the JuMP quick guide, i’ve seen i can use the sum()
function with a condition, like this:
sum(expression for i = I1, j = I2 if cond)
is the same as:
a = zero(AffExpr)
for i = I1
for j = I2
...
if cond
a += expression
end
...
end
end
Does it work if i have another condition inside that first condition? If it does, how can i write it? Using commas to separe the if's
, just like the for's
?
To be more clear, i have this loop in my code i wish to change using the sum()
syntax:
hmax = 25;
Nt = 17;
Yh = zeros(Complex128,Nt,Nt,hmax);
for h = 3:2:hmax
for L = 1:Nt
for C = 1:Nt
for i = 1:Nt
if CONDITION 1
if CONDITION 2
Yh[L,C,h] += first_expression;
end
if CONDITION 3
Yh[L,C,h] += second_expression;
end
end
if CONDITION 4
Yh[L,C,h] += third_expression;
Yh[C,L,h] = Yh[L,C,h];
end
end
end
end
end
I thought in using 3 sum()
here:
1 - The first for the conditions 1 and 2;
2 - The second for the conditions 1 and 3;
3 - The third for the condition 4.