Minimal phase spectral factorization

% A PSD matrix is found which minimizes a weighted trace while obtaining
% fixed sums along the diagonals. Notice the use of a FOR loop to access
% the diagonals of X. A later version of CVX will eliminate the need for
% this by allowing the use of the SPDIAGS function in side models.
% Nevertheless, this example provides an illustration of the use of
% standard Matlab control statements to build models.
%
% Adapted from an example provided in the SeDuMi documentation.

% Generate data
b = [2; 0.2; -0.3];
n = length( b );

% Create and solve model
cvx_begin sdp
    variable X( n, n ) symmetric
    dual variable y{n}
    minimize( ( n - 1 : -1 : 0 ) * diag( X ) );
    for k = 1 : n,
        sum( diag( X, k - 1 ) ) == b( k ) : y{k};
    end
    X >= 0;
cvx_end
y = [ y{:} ]';

% Display resuls
disp( 'The optimal point, X:' );
disp( X )
disp( 'The diagonal sums:' );
disp( sum( spdiags( X, 0:n-1 ), 1 ) );
disp( 'min( eig( X ) ) (should be nonnegative):' );
disp( min( eig( X ) ) )
disp( 'The optimal weighted trace:' );
disp( ( n - 1 : -1 : 0 ) * diag( X ) );
 
Calling SDPT3: 6 variables, 3 equality constraints
------------------------------------------------------------

 num. of constraints =  3
 dim. of sdp    var  =  3,   num. of sdp  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      mean(obj)   cputime
-------------------------------------------------------------------
 0|0.000|0.000|2.6e+00|1.3e+00|3.2e+01| 4.941343e+00| 0:0:00| chol  1  1 
 1|1.000|1.000|4.6e-07|5.4e-02|3.5e+00|-4.793715e-01| 0:0:00| chol  1  1 
 2|1.000|0.906|6.8e-08|9.9e-03|3.9e-01| 2.637395e-01| 0:0:00| chol  1  1 
 3|0.967|1.000|1.2e-08|5.4e-04|1.1e-02| 1.268420e-01| 0:0:00| chol  1  1 
 4|0.945|1.000|3.7e-08|5.4e-05|4.8e-04| 1.229281e-01| 0:0:00| chol  1  1 
 5|0.976|1.000|1.2e-08|5.4e-06|4.7e-05| 1.227472e-01| 0:0:00| chol  1  1 
 6|0.932|1.000|1.4e-09|2.5e-09|2.2e-06| 1.227328e-01| 0:0:00| chol  1  1 
 7|1.000|1.000|1.9e-10|2.8e-10|2.2e-07| 1.227326e-01| 0:0:00| chol  2  2 
 8|1.000|1.000|2.3e-11|3.8e-11|9.6e-09| 1.227326e-01| 0:0:00|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   =  8
 primal objective value =  1.22732571e-01
 dual   objective value =  1.22732561e-01
 gap := trace(XZ)       = 9.60e-09
 relative gap           = 7.71e-09
 actual relative gap    = 7.63e-09
 rel. primal infeas     = 2.26e-11
 rel. dual   infeas     = 3.83e-11
 norm(X), norm(y), norm(Z) = 2.0e+00, 7.6e-01, 2.4e+00
 norm(A), norm(b), norm(C) = 3.1e+00, 3.0e+00, 3.2e+00
 Total CPU time (secs)  = 0.1  
 CPU time per iteration = 0.0  
 termination code       =  0
 DIMACS: 2.3e-11  0.0e+00  4.1e-11  0.0e+00  7.6e-09  7.7e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.122733
The optimal point, X:
    0.0468   -0.0369   -0.3000
   -0.0369    0.0292    0.2369
   -0.3000    0.2369    1.9240

The diagonal sums:
    2.0000    0.2000   -0.3000

min( eig( X ) ) (should be nonnegative):
   1.1049e-09

The optimal weighted trace:
    0.1227