How to deal trace(X^H*A*X) in cvx

I installed cvx2.2, but it seems doesn’t work for my problem.
image

Calling Mosek 9.1.9: 167 variables, 31 equality constraints
For improved efficiency, Mosek is solving the dual problem.

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:34:40)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 31
Cones : 6
Scalar variables : 67
Matrix variables : 2
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 2
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.03
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 31
Cones : 6
Scalar variables : 67
Matrix variables : 2
Integer variables : 0

Optimizer - threads : 6
Optimizer - solved problem : the primal
Optimizer - Constraints : 19
Optimizer - Cones : 6
Optimizer - Scalar variables : 57 conic : 56
Optimizer - Semi-definite variables: 2 scalarized : 172
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 184 after factor : 190
Factor - dense dim. : 0 flops : 6.47e+04
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 3.2e+02 1.0e+06 7.0e+00 0.00e+00 5.000379109e+00 -1.000000000e+00 1.0e+00 0.03
1 1.5e+02 4.9e+05 4.8e+00 -1.00e+00 2.514165073e+00 -2.324738894e+00 4.6e-01 0.11
2 3.3e+01 1.1e+05 2.3e+00 -1.00e+00 -1.521187190e+01 -1.257561415e+01 1.0e-01 0.11
3 5.0e+00 1.7e+04 8.8e-01 -1.00e+00 -1.570619732e+02 -1.007266956e+02 1.6e-02 0.11
4 1.1e+00 3.6e+03 4.1e-01 -1.00e+00 -7.935873698e+02 -5.112220118e+02 3.5e-03 0.11
5 2.4e-01 7.9e+02 1.9e-01 -9.99e-01 -3.804281156e+03 -2.481866377e+03 7.5e-04 0.13
6 5.0e-02 1.7e+02 8.8e-02 -9.97e-01 -1.816933896e+04 -1.194071162e+04 1.6e-04 0.13
7 9.3e-03 3.1e+01 3.7e-02 -9.86e-01 -9.396112106e+04 -6.194791716e+04 2.9e-05 0.13
8 4.6e-03 1.5e+01 2.2e-02 -8.21e-01 -1.277867781e+05 -8.254318154e+04 1.5e-05 0.13
9 2.8e-03 9.4e+00 7.8e-03 6.45e-01 -2.209806435e+04 -6.571195434e+03 9.0e-06 0.14
10 1.3e-03 4.3e+00 2.2e-03 7.43e-01 1.464638187e+04 2.073647132e+04 4.1e-06 0.14
11 5.8e-04 1.9e+00 6.8e-04 1.02e+00 3.317949207e+04 3.598698077e+04 1.8e-06 0.14
12 1.6e-04 5.4e-01 1.1e-04 1.06e+00 3.999012913e+04 4.085263849e+04 5.1e-07 0.14
13 5.1e-05 1.7e-01 1.9e-05 1.09e+00 4.308746442e+04 4.336089313e+04 1.6e-07 0.14
14 2.4e-05 7.9e-02 6.3e-06 9.48e-01 4.375905009e+04 4.390292842e+04 7.5e-08 0.16
15 5.5e-06 1.8e-02 5.7e-07 1.25e+00 4.439602605e+04 4.441747984e+04 1.8e-08 0.16
16 2.1e-06 6.8e-03 1.4e-07 1.02e+00 4.447779134e+04 4.448657135e+04 6.5e-09 0.16
17 1.5e-07 5.1e-04 1.9e-09 1.26e+00 4.453268085e+04 4.453299079e+04 4.9e-10 0.16
18 8.9e-12 2.9e-08 6.4e-13 1.01e+00 4.453482092e+04 4.453482187e+04 2.5e-12 0.17
19 2.7e-12 5.1e-10 3.5e-13 1.00e+00 4.453473541e+04 4.453473540e+04 8.9e-15 0.17
Optimizer terminated. Time: 0.19

Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 4.4534735407e+04 nrm: 8e+04 Viol. con: 3e-06 var: 1e-06 barvar: 0e+00 cones: 7e-11
Dual. obj: 4.4534735392e+04 nrm: 6e+04 Viol. con: 0e+00 var: 3e-06 barvar: 8e-12 cones: 0e+00
Optimizer summary
Optimizer - time: 0.19
Interior-point - iterations : 19 time: 0.17
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Solved
Optimal value (cvx_optval): -44534.7

t1 =

4.3436e+04 + 1.0236e-08i

t2 =

 1

Start a fresh session of MATLAB. Copy and paste your code into the command window and show the output in that window.

You apparently are running a different code than what was in your post which is what I ran. Your lack of configuration control does not serve to your advantage, or economical use of my time.

image

Whar is the output of
which -all square_pos

Here is mine:

>> which -all square_pos
C:\cvx_2.2_1148\functions\square_pos.m
C:\cvx_2.2_1148\functions\@cvx\square_pos.m  % cvx method

Same as you.

Results from
which -all square

Mine are:

>> which -all square
C:\cvx_2.2_1148\functions\square_\square.m
C:\cvx_2.2_1148\functions\@cvx\square.m     % cvx method

I suspect you have another version of square which is causing the wrong result. Perhas this from Signal Processing Toolbox Square wave - MATLAB square .

Here is the square_pos at ```
C:\cvx_2.2_1148\functions\square_pos.m

function y = square_pos( x )

%SQUARE_POS Square of positive part.
% SQUARE_POS(X) is the square of the postive parts of the elements of X;
% i.e., SQUARE_POS(X)=MAX(X,0).^2. X must be real.
%
% Disciplined convex programming information:
% SQUARE_POS(X) is convex and nondecreasing in X. Thus when used in
% CVX expressions, X must be convex (or affine).

narginchk(1,1);
if ~isreal( x ),
error( ‘Argument must be real.’ );
end

y = square( max( x, 0 ) );

% Copyright 2005-2016 CVX Research, Inc.
% See the file LICENSE.txt for full copyright information.
% The command ‘cvx_where’ will show where this file is located.

but square(x) and square_pos(x) are two different function.

square_pos calls square,in your case, the Signal Processing Toolbox version,

The version of square_pos called for CVX arguments will not encounter this. You could just avoid calling square_pos with numerical arguments, because it is not necessary, anyway. norm(...,,'fro')^2 works just fine for numerical arguments.

Here is the definitive word on the subject. Read the full thread, not just the portion displayed below.

I see, thank you very much Mark.