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 inside Nested loops

**ali**(ali) #1

**Mark_L_Stone**(Mark L. Stone) #2

CVX can be used inside nested `for`

and `while`

loops. Do you have a more specific question?

**ali**(ali) #3

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

**susan**#4

Hi ali,

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

Thanks

**Mark_L_Stone**(Mark L. Stone) #5

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
```