# SDP constraint must be square

Hello,

I am working on a convex optimization problem using the CVX toolbox, where I employ the Big-M formulation to address a SDP problem. My declared variables within the cvx_begin sdp environment are:

variable W(M, M, N) hermitian semidefinite
variable W_tilde(M, M, N, J) hermitian semidefinite
variable c(N, J) nonnegative


I constrain the variable c to be between 0 and 1 as it is a continuous variable. However, I encounter the following error when I run my program:

Error using cvxprob/newcnstr
SDP constraint must be square.

Error in variable (line 191)
newcnstr( prob, v, 0, '>=', false );


This error seems to be associated with the variable c(N, J). Could you provide guidance on how to resolve this issue? Thank you!

Could you show the code line that threw this error ?

    cvx_begin sdp
variable W(M, M, N) hermitian semidefinite
variable W_tilde(M, M, N, J) hermitian semidefinite
variable c(N, J) nonnegative
expressions y(N, J) z(N, J) R(N, 1)

% Define the objective function
for n = 1:N
W_int_n = W_int(:, :, n);
W_n = W(:, :, n);
H_n = squeeze(H(n, :, :));

% Initialize x
x = cvx(zeros(1, 1));

% Loop over j
for j = 1:J
W_tilde_nj = W_tilde(:, :, n, j);
F_nj = squeeze(F(n, j, :, :));
alpha_nj = alpha(n, j);

% Update x
x = x + alpha_nj * trace(F_nj * W_tilde_nj)/sigma;
end

% Calculate constant terms
tr_Hn_Wn = trace(H_n * W_n);
tr_Hn_Wintn = trace(H_n * W_int_n);

% Update R
R(n) = real(log(x + beta_sic * tr_Hn_Wn + 1) / log2) ...
- real(log(beta_sic * tr_Hn_Wintn + 1) / log2) ...
- real(trace((beta_sic_log2 * H_n / (tr_Hn_Wintn + 1 / beta_sic)) * (W_n - W_int_n)));
end

obj = sum(R);
maximize(obj)

subject to
for n = 1:N
W_n = W(:, :, n);
H_n = squeeze(H(n, :, :));

for j = 1:J
G_jn = squeeze(G(n, j, :, :));
F_nj = squeeze(F(n, j, :, :));
W_tilde_nj = W_tilde(:, :, n, j);
a_m = squeeze(a(n, j, :));
alpha_nj = alpha(n, j);

y(n, j) = alpha_nj * trace(a_m * a_m' * W_tilde_nj);
z(n, j) = alpha_nj * trace(F_nj * W_tilde_nj);

% C3
real(trace(G_jn * W_tilde_nj) - P_th/(1 - alpha_nj)) >= 0;
imag(trace(G_jn * W_tilde_nj) - P_th/(1 - alpha_nj)) == 0;

% C5
real(W_tilde_nj - c(n, j) * PmaxEye) <= 0;
imag(W_tilde_nj - c(n, j) * PmaxEye) == 0;

% C6
real(W_tilde_nj - W_n) <= 0;
imag(W_tilde_nj - W_n) == 0;

% C7
real(W_tilde_nj - W_n + (1 - c(n, j)) * PmaxEye) >= 0;
imag(W_tilde_nj - W_n + (1 - c(n, j)) * PmaxEye) >= 0;
end
% C2
real((trace(H_n * W_n) / (gamma_t_th*sigma)) - sum(z, 2)/sigma - 1) >= 0;
imag((trace(H_n * W_n) / (gamma_t_th*sigma)) - sum(z, 2)/sigma - 1) >= 0;

% C4
trace(W_n) - Pmax <= 0;
end

% C1
real(sum(y, 1)/sigma - gamma_s_th) >= 0;
imag(sum(y, 1)/sigma - gamma_s_th) == 0;

% C8
sum(sum(c - c_int.^2 - 2 * c_int .* (c - c_int))) <= 0;

% C9
0 <= c <= 1;
cvx_end


Also, the error in the command window is given by:

Error using cvxprob/newcnstr
SDP constraint must be square.

Error in variable (line 191)
newcnstr( prob, v, 0, '>=', false );

Error in Optimiz_W_C (line 40)
variable c(N, J) nonnegative


try variable c(N,J) ; c(:)>=0; rather than simply “variable c(N,J) nonnegative”. because i guess the latter was like c>=0, which means c is semidefinte in sdp mode, instead of c being nonnegative element-wise.

I haven;t checked your code, and it is not reproducible, but your code uses squeeze a lot. Perhaps you have squeezed out a dimension you shouldn’t have, in which case maybe reshape will do what you need. I would suggest you try using whos and perhaps just typing “things” at the command line and seeing how CVX characterizes them. Look for anything which doesn’t have the needed dimensions.

Thank you for your response. Given the nature of the problem as an SDP, it does not accommodate non-square matrices. Here, c(N, J) is a non-square matrix. I employed the Big-M formulation once again. Thus, I defined:

\tilde{W}_k(n) = c_k(n) \cdot W(n),

where W(n) = w(n) \cdot w'(n) and 0 \leq c_k(n) \leq 1 is a scalar. Do you have any advice or suggestions on handling non-square matrices in such scenarios?

You need to tell us clearly what the mathematical specification of your optimization problem is. it must be convex, or CVX can’t be used. When you have clearly stated a convex optimization problem, then perhaps readers can help you formulate if for CVX, if they know how.