Exercise 4.38(b): Linear matrix inequalities with one variable

% From Boyd & Vandenberghe, "Convex Optimization"
% Joëlle Skaf - 09/26/05
%
% Finds the optimal t that would maximize c*t while still having A - t*B
% positive semidefinite by solving the following SDP:
%           minimize    c*t
%               s.t.    t*B <= A
% c can either be a positive or negative real number

% Generate input data
randn('state',0);
n = 4;
A = randn(n); A = 0.5*(A'+A); %A = A'*A;
B = randn(n); B = B'*B;
% can modify the value of c (>0 or <0)
c = -1;

% Create and solve the model
cvx_begin sdp
    variable t
    minimize ( c*t )
    A >= t * B;
cvx_end

% Display results
disp('------------------------------------------------------------------------');
disp('The optimal t obtained is');
disp(t);
 
Calling sedumi: 10 variables, 1 equality constraints
   For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 1, order n = 5, dim = 17, blocks = 2
nnz(A) = 10 + 0, nnz(ADA) = 1, nnz(L) = 1
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            8.07E+00 0.000
  1 :  -6.80E-01 1.51E+00 0.000 0.1867 0.9000 0.9000   0.45  1  1  1.9E+00
  2 :  -2.18E+00 3.25E-01 0.000 0.2156 0.9000 0.9000   0.04  1  1  1.1E+00
  3 :  -1.52E+01 2.54E-02 0.000 0.0781 0.9900 0.9900  -0.60  1  1  5.7E-01
  4 :  -4.19E+01 2.24E-03 0.000 0.0881 0.9900 0.9900  -0.27  1  1  1.2E-01
  5 :  -4.72E+01 3.75E-04 0.000 0.1678 0.9000 0.9000   0.96  1  1  2.0E-02
  6 :  -4.83E+01 8.86E-07 0.149 0.0024 0.9955 0.9990   0.99  1  1  1.5E-04
  7 :  -4.83E+01 1.70E-07 0.000 0.1923 0.9000 0.6868   1.00  1  1  2.9E-05
  8 :  -4.83E+01 4.71E-09 0.058 0.0277 0.9903 0.9900   1.00  1  1  6.7E-07
  9 :  -4.83E+01 6.95E-10 0.000 0.1475 0.9000 0.8343   1.00  1  1  1.3E-07
 10 :  -4.83E+01 3.33E-11 0.360 0.0479 0.9905 0.9900   1.00  1  1  5.6E-09

iter seconds digits       c*x               b*y
 10      0.1   Inf -4.8318982940e+01 -4.8318982370e+01
|Ax-b| =   6.4e-10, [Ay-c]_+ =   8.5E-09, |x|=  1.1e+02, |y|=  2.6e+02

Detailed timing (sec)
   Pre          IPM          Post
2.000E-02    1.000E-01    0.000E+00    
Max-norms: ||b||=1.877157e-01, ||c|| = 2.895108e+00,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +48.354
------------------------------------------------------------------------
The optimal t obtained is
  -48.3540