I am using trace in my CVX (MATLAB) code. Sometimes it is working fine, but sometimes it is showing some errors. Error message is as follows-
"trace" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable. A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.
I searched in CVX website and I found this-
trace(Z) is valid only if the elements along the diagonal have the same curvature.
I could not make sense out of it. Looking forward for any generous suggestion.
I excerpt a part of my MATLAB code below to clearly state my problem.
The program where it is working properly-
%% Calling CVX Package
G = zeros((M+1)*d,(M+1)*d);
for i = 0:M
G(i*d+(1:d),i*d+(1:d)) = eye(d);
end
cvx_precision best;
cvx_begin
variable G((M+1)*d,(M+1)*d) semidefinite % Defining variables
minimize(trace(C*G)) % Objective function
subject to
% Constraints
for i = 0:M
G(i*d+(1:d),i*d+(1:d)) == eye(d);
end
cvx_end
The program where it is giving errors-
%% Calling CVX Package
Q = zeros(N,N);
Mij = zeros(N,N);
cvx_precision best;
cvx_begin
variable Q(N,N) semidefinite % Defining variables
minimize(trace(Q)) % Objective function
subject to
% Constraints
for i = 1:N-1
for j = i:N
if E(i,j) ~= 0
Mij = Mij-Mij;
Mij(i,j) = -1;
Mij(j,i) = -1;
Mij(i,i) = 1;
Mij(j,j) = 1;
trace(Mij*Q) = E(i,j);
end
end
end