```% This script finds a Toeplitz Hermitian PSD matrix that is closest to a
% given Hermitian matrix, as measured by the Frobenius norm. That is, for
% a given matrix P, it solves:
%    minimize   || Z - P ||_F
%    subject to Z >= 0
%
% Adapted from an example provided in the SeDuMi documentation. Notice
% the use of SDP mode to simplify the semidefinite constraint.

% The data. P is Hermitian, but is neither Toeplitz nor PSD.
P = [ 4,     1+2*j,     3-j       ; ...
1-2*j, 3.5,       0.8+2.3*j ; ...
3+j,   0.8-2.3*j, 4         ];

% Construct and solve the model
n = size( P, 1 );
cvx_begin sdp
variable Z(n,n) hermitian toeplitz
dual variable Q
minimize( norm( Z - P, 'fro' ) )
Z >= 0 : Q;
cvx_end

% Display resuls
disp( 'The original matrix, P: ' );
disp( P )
disp( 'The optimal point, Z:' );
disp( Z )
disp( 'The optimal dual variable, Q:' );
disp( Q )
disp( 'min( eig( Z ) ), min( eig( Q ) ) (both should be nonnegative, or close):' );
disp( sprintf( '   %g   %g\n', min( eig( Z ) ), min( eig( Q ) ) ) );
disp( 'The optimal value, || Z - P ||_F:' );
disp( norm( Z - P, 'fro' ) );
disp( 'Complementary slackness: Z * Q, should be near zero:' );
disp( Z * Q )
```
```
Calling SDPT3 4.0: 20 variables, 6 equality constraints
For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

num. of constraints =  6
dim. of sdp    var  =  6,   num. of sdp  blk  =  1
dim. of socp   var  = 11,   num. of socp blk  =  1
*******************************************************************
SDPT3: Infeasible path-following algorithms
*******************************************************************
version  predcorr  gam  expon  scale_data
HKM      1      0.000   1        0
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
0|0.000|0.000|1.8e+01|2.7e+00|7.4e+02| 1.260000e+02  0.000000e+00| 0:0:00| chol  1  1
1|0.332|1.000|1.2e+01|3.3e-02|4.7e+02| 9.616817e+01 -4.813672e+01| 0:0:00| chol  1  1
2|1.000|1.000|2.4e-07|3.3e-03|3.1e+01| 4.813335e+00 -2.613716e+01| 0:0:00| chol  1  1
3|1.000|0.793|9.3e-08|9.5e-04|7.1e+00| 2.763897e+00 -4.276057e+00| 0:0:00| chol  1  1
4|0.780|1.000|2.8e-08|3.3e-05|1.9e+00|-9.411558e-01 -2.847823e+00| 0:0:00| chol  1  1
5|0.979|0.962|8.9e-10|4.5e-06|6.6e-02|-1.414992e+00 -1.480982e+00| 0:0:00| chol  1  1
6|0.983|0.989|1.3e-10|3.8e-07|9.5e-04|-1.450304e+00 -1.451248e+00| 0:0:00| chol  1  1
7|0.939|0.983|9.0e-10|3.9e-08|3.9e-05|-1.450788e+00 -1.450827e+00| 0:0:00| chol  1  1
8|0.932|0.984|2.0e-09|6.7e-10|1.8e-06|-1.450803e+00 -1.450804e+00| 0:0:00| chol  1  1
9|0.981|0.990|1.0e-10|6.6e-11|5.7e-08|-1.450803e+00 -1.450804e+00| 0:0:01|
stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
number of iterations   =  9
primal objective value = -1.45080348e+00
dual   objective value = -1.45080354e+00
gap := trace(XZ)       = 5.69e-08
relative gap           = 1.46e-08
actual relative gap    = 1.45e-08
rel. primal infeas (scaled problem)   = 1.04e-10
rel. dual     "        "       "      = 6.61e-11
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual     "        "       "      = 0.00e+00
norm(X), norm(y), norm(Z) = 1.9e+00, 3.2e+00, 6.8e+00
norm(A), norm(b), norm(C) = 5.5e+00, 2.0e+00, 8.0e+00
Total CPU time (secs)  = 0.51
CPU time per iteration = 0.06
termination code       =  0
DIMACS: 1.0e-10  0.0e+00  1.0e-10  0.0e+00  1.4e-08  1.5e-08
-------------------------------------------------------------------

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +1.4508

The original matrix, P:
4.0000 + 0.0000i   1.0000 + 2.0000i   3.0000 - 1.0000i
1.0000 - 2.0000i   3.5000 + 0.0000i   0.8000 + 2.3000i
3.0000 + 1.0000i   0.8000 - 2.3000i   4.0000 + 0.0000i

The optimal point, Z:
4.2827 + 0.0000i   0.8079 + 1.7342i   2.5574 - 0.7938i
0.8079 - 1.7342i   4.2827 + 0.0000i   0.8079 + 1.7342i
2.5574 + 0.7938i   0.8079 - 1.7342i   4.2827 + 0.0000i

The optimal dual variable, Q:
0.3366 + 0.0000i  -0.0635 - 0.2866i  -0.3051 + 0.1422i
-0.0635 + 0.2866i   0.2561 + 0.0000i  -0.0635 - 0.2866i
-0.3051 - 0.1422i  -0.0635 + 0.2866i   0.3366 + 0.0000i

min( eig( Z ) ), min( eig( Q ) ) (both should be nonnegative, or close):
1.08289e-08   2.176e-09

The optimal value, || Z - P ||_F:
1.4508

Complementary slackness: Z * Q, should be near zero:
1.0e-05 *

0.0915 - 0.1253i  -0.1237 - 0.0530i  -0.0286 + 0.1516i
0.0448 - 0.2020i  -0.1790 - 0.0000i   0.0448 + 0.2020i
-0.0286 - 0.1516i  -0.1237 + 0.0530i   0.0915 + 0.1253i

```