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

The code is the following:

k = 500;

d = 2;

theta=ones(d,1);

X = rand(d,k);

X(:,1) = ones(d,1);

Y = X(:,1) - X;

cvx_begin

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;

end

a’*ones(k,1) == 1;

a >= 0;

cvx_end

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?

Thanks!