# Trace of $S^{-2}$ in cvx

Why cvx cannot solve the following problem:

cvx_solver sdpt3
cvx_begin quiet
variable S(m,m) symmetric;
S == semidefinite(m);
minimize (trace(S)+trace_inv(square(S)));
cvx_end


After running this I get the following error:

??? Error using ==> cvx.trace_inv at 9
Input must be affine.


Actually the function f(S)=\mathrm{trace}(S)+\mathrm{trace}(S^{-2}) where S\in \mathcal{M}_{m,m} symmetric positive definite is convex because
\frac{\partial^2 f}{\partial S^2}=6S^{-4} is symmetric positive definite.
So I wonder why the input of trace_inv should be affine.

I even tried to solve the problem in different manner as follow:

cvx_solver sdpt3
cvx_begin quiet
variable Q(m,m) symmetric;
Q == semidefinite(m);
minimize (trace_sqrtm(Q) + trace_inv(Q));
cvx_end
S=sqrtm(Q);


but I got the following error:

??? Undefined function or method 'schur' for input arguments of type 'cvx'.

Error in ==> sqrtm at 33
[Q, T] = schur(A,'complex');  % T is complex Schur form.


This means that the principal square root matrix of Q, i.e. sqrtm(Q), has some complex entries which is impossible since Q is Symmetric Positive Definite matrix whose eigenvalues have nonnegative real part.

Please understand that you simply cannot expect CVX to accept any expression that you want even if you prove it is convex. CVX does not claim to solve arbitrary convex optimization problems. Rather, it solves disciplined convex programs. There is a difference, and a successful user of CVX must fully understand that difference.

The rules by which CVX accepts expressions are fully documented in the section The DCP ruleset. The list of functions you are allowed to start from is given in the reference guide. This is the grammar, if you will, by which CVX parses problems. There are concrete mathematical reasons underneath the hood why CVX must limit itself to those rules. You are welcome to read the supporting papers on the subject to ask why, our you can just trust me

So to be frank, you should not be wondering why CVX would not accept this. The answer is clearly laid out in the documentation. If you wish to solve your problem, you will have to figure out how to express it in a manner compliant with the rules. Entering arbitrary problems into CVX, even ones you know are convex, is certain to lead to continued frustration.

Your calculus is incorrect. The Hessian of f(S) is a mapping from the symmetric matrices into itself, so the Hessian cannot possibly be a matrix. It may still be convex, but you have not proven it. Nevertheless, I have a more comprehensive answer below.

As for the weird message from ‘sqrtm’, this is simply caused by the fact that sqrtm is not implemented for CVX, because it is not a convex or concave. (Indeed it is a matrix function so it cannot be.)

I think that this cannot be solvable using cvx even if I write my function in a different manner since the relationship between the input of trace and trace_inv lasts and still convex. That is, cvx would always consider that I have a convex equality Q=S^2 where Q is the input of trace_inv and S is the input of the trace operator.