Problem with cvx code to minimise trace

Hi! I am new to cvx and am having trouble with the following.

I need to find a matrix X which minimizes the below. When I work with 3x3 matrices the code works fine, but when I try 9x9 matrices I do not get a solution even though I know there is one. Any help would be greatly appreciated

B1=[1 1 0; 0 1 1;1 0 1];
J1=ones(3);
J2=ones(9);
B2=kron(B1,B1);
B2bar=0.5*(B2+B2’);
B1bar=0.5*(B1+B1’);

n=9;
cvx_solver
cvx_begin sdp
variable X(n,n) symmetric;
minimize( trace( B2barX ) );
subject to
X==semidefinite(n);
X>=0;
trace( X
J2 ) == 1;
cvx_end

Your problem as entered is unbounded. Perhaps the problem you provided for n = 3 is not unbounded?

You can omit the objective function (minimize command) and get a feasible solution. Alternatively, you can add another constraint, such as norm(X,inf) <= 10, which makes the problem bounded (or perhaps change you input data).

Note that although I don’t think it does any harm, your specification of both X == semidefinite(n) and X >= 0 (under sdp mode, which you have specified) is redundant. Either one by itself would be sufficient (and sdp mode is not needed if you don’t use X >= 0).