# How to express the sum(eig(V)) in the cvx?

Declare a variable of size M*M in the cvx.
eig(V) returns the eigenvalues of the declared ‘V’, which is a vector.

The corresponding function is sum(eig(V)).

Is the above function is a convex function?

If it is a convex function, how to express it in the cvx?

Sum of the eigenvalues of a matrix is identical to the trace of the matrix. So should not you just sum the diagonal elements.

1 Like

@Erling is correct. That result is one of my favorites in all of math, right up there iwith Jensen’s inequality.

There is howeverr a dumb way to do this in CVX, which is not dumb when you don’t want the sum of all the eigenvalues.

help lambda_sum_largest

lambda_sum_largest Sum of the k largest eigenvalues of a symmetric matrix.

``````  For square matrix X, lambda_sum_largest(X,K) is SUM_LARGEST(EIG(X),k)
if X is Hermitian or symmetric and real; and +Inf otherwise.

An error results if X is not a square matrix.

Disciplined convex programming information:
lambda_sum_largest is convex and nonmonotonic (at least with
respect to elementwise comparison), so its argument must be affine.``````
1 Like

Thanks! @Erling @Mark_L_Stone

Actually, the ‘lambda_sum_largest(X,K)’ is what I need.