title: trace in CVX package
body: <p>I am using <em>trace</em> in my <em>CVX (MATLAB)</em> code. Sometimes it is working fine, but sometimes it is showing some errors. Error message is as follows-</p>
  
  <blockquote>
    <p>"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.</p>
  </blockquote>
  
  <p>I searched in CVX website and I found this- </p>
  
  <blockquote>
    <p><em>trace(Z)</em> is valid only if the elements along the diagonal have the same curvature.</p>
  </blockquote>
  
  <p>I could not make sense out of it. Looking forward for any generous suggestion.</p>
  
  <p>I excerpt a part of my MATLAB code below to clearly state my problem.</p>
  
  <p>The program where it is working properly-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>%% 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</code></pre>
  </div>
  </div>
  </p>
  
  <p>The program where it is giving errors-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>%% 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</code></pre>
  </div>
  </div>
  </p>