Minimum volume ellipsoid covering a finite set

% Section 8.4.1, Boyd & Vandenberghe "Convex Optimization"
% Almir Mutapcic - 10/05
% (a figure is generated)
%
% Given a finite set of points x_i in R^2, we find the minimum volume
% ellipsoid (described by matrix A and vector b) that covers all of
% the points by solving the optimization problem:
%
%           maximize     log det A
%           subject to   || A x_i + b || <= 1   for all i
%
% CVX cannot yet handle the logdet function, but this problem can be
% represented in an equivalent way as follows:
%
%           maximize     det(A)^(1/n)
%           subject to   || A x_i + b || <= 1   for all i
%
% The expression det(A)^(1/n) is SDP-representable, and is implemented
% by the MATLAB function det_rootn().

% Generate data
x = [ 0.55  0.0;
      0.25  0.35
     -0.2   0.2
     -0.25 -0.1
     -0.0  -0.3
      0.4  -0.2 ]';
[n,m] = size(x);

% Create and solve the model
cvx_begin
    variable A(n,n) symmetric
    variable b(n)
    maximize( det_rootn( A ) )
    subject to
        norms( A * x + b * ones( 1, m ), 2 ) <= 1;
cvx_end

% Plot the results
clf
noangles = 200;
angles   = linspace( 0, 2 * pi, noangles );
ellipse  = A \ [ cos(angles) - b(1) ; sin(angles) - b(2) ];
plot( x(1,:), x(2,:), 'ro', ellipse(1,:), ellipse(2,:), 'b-' );
axis off
 
Calling SeDuMi: 33 variables (2 free), 24 equality constraints
------------------------------------------------------------------------
SeDuMi 1.1 by AdvOL, 2005 and Jos F. Sturm, 1998, 2001-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Split 2 free variables
eqs m = 24, order n = 23, dim = 43, blocks = 9
nnz(A) = 72 + 0, nnz(ADA) = 354, nnz(L) = 189
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            8.47E-001 0.000
  1 :  2.61E-001 2.06E-001 0.000 0.2434 0.9000 0.9000   2.99  1  1  5.6E-001
  2 : -9.13E-001 6.93E-002 0.000 0.3360 0.9000 0.9000   0.76  1  1  2.6E-001
  3 : -2.29E+000 1.56E-002 0.000 0.2252 0.9000 0.9000   0.42  1  1  7.6E-002
  4 : -2.66E+000 1.54E-003 0.000 0.0985 0.9900 0.9900   0.91  1  1  7.7E-003
  5 : -2.68E+000 2.96E-004 0.000 0.1927 0.9000 0.9000   1.00  1  1  1.5E-003
  6 : -2.68E+000 9.15E-006 0.311 0.0309 0.9902 0.9900   1.00  1  1  9.2E-005
  7 : -2.68E+000 1.04E-006 0.000 0.1139 0.9000 0.8650   1.00  1  1  1.9E-005
  8 : -2.68E+000 2.94E-008 0.000 0.0282 0.9900 0.9763   1.00  1  1  5.3E-007
  9 : -2.68E+000 1.26E-009 0.000 0.0429 0.9902 0.9900   1.00  2  2  2.3E-008
 10 : -2.68E+000 7.90E-011 0.191 0.0627 0.9900 0.9529   1.00  2  2  1.5E-009

iter seconds digits       c*x               b*y
 10      0.1   Inf -2.6839853947e+000 -2.6839853934e+000
|Ax-b| =  1.1e-009, [Ay-c]_+ =  7.6E-010, |x|= 1.1e+001, |y|= 2.5e+000

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    1.102E-001    0.000E+000    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1145.68.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +2.68399