Invalid quadratic form of second moment of distribution

I have some 2D distribution descretized to equal areas. I am trying to minimize the maximum eigenvalue of the second moment which I know will be positive definite. I have n variables d_i which represent the density at each point z_i (known) and t which represents the largest eigenvalue of the second moment. There are also some constraints on the density and mass

  • m is the mass, a function of d_i
  • \mu the first moment, a function of m, d_i, z_i

The second moment should be the PSD matrix defined by

\Sigma= \sum_{i = 1}^n d_i * (z_i - \mu)(z_i - \mu)^T

minimize t
\Sigma <= tI
m == m_{total}
d_i <= d_{max}

However, I get the Invalid quadratic form(s): not a square. error. I see why this is happening, but I am unsure to get around this.

function Sigma = second_moment(d, Z, mu)
    Sigma = d(1) * (Z(:, 1) - mu) * (Z(:, 1) - mu)';
    for i = 2:len(d)
       Sigma = Sigma + d(i) * (Z(:, i) - mu) * (Z(:, i) - mu)';

It will help us, and you, if you write out all the math explicitly (including for \mu), making clear what are the optimization variables vs. input data. Then prove that \Sigma is jointly convex in the optimization variables … if indeed it is.