Problem inefficiency for loop constraints problem Matlab CVX

I am trying to solve a convex optimization problem with the CVX MATLAB package.

The code is the following:

k = 500;
d = 2;
X = rand(d,k);
X(:,1) = ones(d,1);
Y = X(:,1) - X;

variable a(k)
A = X*diag(ones(1,k).*a’)*X’;
variable z
minimize z
subject to
for i = 2:k
z >= matrix_frac(Y(:,i),A)/(theta’*Y(:,i))^2;
a’*ones(k,1) == 1;
a >= 0;
The code works but the problem is in the efficiency.

In particular, the for loop in the constraints makes it very inefficient since the number of constraints grows linearly with the parameter k. Is there any more efficient way to incorporate the constraints in the problem that avoids this for loop?


matrix_frax can’t be further vectorized.

But perhaps you could declare variable a_inverse instead of a. Then can the constraint in the for lop be vectorized? I haven’t worked it out, so I’m not sure. That’s really a matter of MATLAB vectorization - if you can figure out how to do it with MATLAB double precision variables, it ought to work with CVX variables, provided implicit expansion, which is not supported in CVX, is not used. The remaining constraints should be easy to modify.

1 Like