Can I have different constraints in a loop?


(saeed ) #1

in a constraint, a paremeter gets different values. indeed this constraint
itself involves different constraints each of one is related to a distinct value of the
parameter. So I have written it in a loop.here, the question is that since for each
cycle of the loop the constraint is different, does the whole loop involve all constraints?
in other words, are all constraints effect on variables kept and saved to give the correct
value of variables or not? if not, does it mean that I have to write the constraint
for each parameter separately? the loop is as below
z, v and q are cvx variables which should be optimized

for k=1:K
    sum_ve=0;
    for kk=1:K
        if k~=kk
            sum_ve=sum_ve+quad_over_lin(A2(:,:,k,kk)*v,q(k));
        end
    end
    Qphi_i=sqrtm(phi(:,:,k));
    sum_ve=sum_ve+sigma2*norm(Qphi_i*v)+sigma2;
    gamak*sum_ve-g(k)<=z   
end

for each k, sum_ve and g(k) are different. are all constraints effects on variables kept?
note that if we use sum_ve(k) instead of sum_ve, we will have an error as below

> The following error occurred converting from cvx to double:
> Error using double
> Conversion to double from cvx is not possible.

(Mark L. Stone) #2

Prior to the first for loop, add the statement
expression sum_ve(K)
and use sum_ve(k) instead of sum_ve.
See http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders


(saeed ) #3

thank you very much.