CVX inside Nested loops

Hi,
Can i use CVX inside nested loops? For example
for i = 1: 10
for j = 1: 4
while n < 100



cvx_begin


cvx_end
end
end
end

CVX can be used inside nested for and while loops. Do you have a more specific question?

1 Like

hi,
Thanks for your answer
When i run my program, it doesn’t work well. It works only for first i, and first j, and whole while loop;
i thought it’s because of CVX, but it wasn’t. I fixed it now.
Thanks a lot

Hi ali,

Does your variable of interest (cvx optimization variable) depend on i and j? If so, how did you define that?

Thanks

One optimization problem:

cvx_begin
variable A(3,3)
minimize(A(1,2)+A(3,2))
% insert constraints
cvx_end

6 optimization problems:

% A in a MATLAB numerical matrix
for i=1:2 
for j=1:3
cvx_begin
minimize(x^2 + A(i,j)*x))
% insert constraints
cvx_end
% Store results for this combination of i and j
end
end