How to write this with CVX code

diag(Xc)*D*diag(Xc)'
Where D is a matrix, and non diagonal lines also have values,Xc is a multidimensional complex variable

Is D hermitian semidefinite? Otherwise this wont’ be convex. Although if D is hermitian negative semidefinite, it would be concave. If neither of those, the expression can’t be used in CVX.

Yes,D is hermitian semidefinite,so I want to know how to write this with CVX,This problem has been bothering me for a long time. Thank you very much for your reply and help

You haven’t told us exactly what the form of Xc is. What you need is
column_vector_conjugate_transpose*D*column_vector .
The multiplications must be conformal, which they are in my code. Your code is non-conformal, because diag(matrix) is a column vector, not a row vector., whether in CVX or MATLAB, and the (1st) argument of diag must be 2D, not 3D or higher.

The following would work:

variable Xc(5,5,3) complex
diag(Xc(:,:,1))'*D*diag(Xc(:,:,1))
diag(Xc(:,:,2))'*D*diag(Xc(:,:,2))
diag(Xc(:,:,3))'*D*diag(Xc(:,:,3))

Otr you could use
quad_form(diag(Xc(:,:,1)),D)
etc.

If the off-diagonal of the Xc slices is never used, you could instead make Xc a 5 by 3 array in this example, and use
Xc(:,1)'*D*Xc(:,1)
etc.

clc; clear all
N=128;
U_H=eye(N);
cvx_begin
      variable x(N, 1) complex % 复数变量 x
      minimize(diag(x)*U_H*diag(x)');              
cvx_end

Snipaste_2023-12-01_23-21-04

The above is my question. An error occurred while running the code, where a multiplication sign cannot be used. Xc is a 128 dimensional complex variable. How can this error be resolved,

My previous post was correct given what you stated. In your most recent post, x is a vector. In MATLAB and CVX, diag(vector) is a diagonal matrix; hence the error message you received.

Perhaps you want
minimize(x'*U_H*x)
which is just a standard quadratic forum, and is essentially athe same s the suggestion in my previous post, altered to reflectx now being a vector, not a matrix.

Perhaps there is confusion as to what is meant by “multidimensional”. In MATLAB and CVX, is this is usually interpreted as the variable being an array having at least 3 dimensions,. and certainly at least 2. An 128 by 1 vector is usually not considered to be a multidimensional variable, but a 128 by 128 by 3 variable would be.

Thank you very much for your answer. I understand your previous post. Now, I would like to ask if the above question can be solved using CVX. If so, how can I write a covariance matrix related to the independent variable in CVX。

Have you formulated a convex optimization problem? That is your responsibility. Perhaps you need to reread, very carefully, the link previously provided.

You might find the material in Convex Optimization – Boyd and Vandenberghe to be of assistance. For example, Exercise 7.4. Or you might not.

I’ll check if my model is convex carefully.Thank you very much for your help.