Example 8.4: One free point localization

% Section 8.7.1, Boyd & Vandenberghe "Convex Optimization"
% Joelle Skaf - 10/23/05
%
% K fixed points (u1,v1),..., (uK,vK) in R^2 are given and the goal is to place
% one additional point (u,v) such that:
% 1) the L1-norm is minimized, i.e.
%           minimize    sum_{i=1}^K ( |u - u_i| + |v - v_i| )
%    the solution in this case is any median of the fixed points
% 2) the L2-norm is minimized, i.e.
%           minimize    sum_{i=1}^K ( |u - u_i|^2 + |v - v_i|^2 )^.5
%    the solution in this case is the Weber point of the fixed points

% Data generation
n = 2;
K = 11;
randn('state',0);
P = randn(n,K);

% L1 - norm
fprintf(1,'Minimizing the L1-norm of the sum of the distances to fixed points...');

cvx_begin
    variable x1(2)
    minimize ( sum(norms(x1*ones(1,K) - P,1)) )
cvx_end

fprintf(1,'Done! \n');

% L2 - norm
fprintf(1,'Minimizing the L2-norm of the sum of the distances to fixed points...');

cvx_begin
    variable x2(2)
    minimize ( sum(norms(x2*ones(1,K) - P,2)) )
cvx_end

fprintf(1,'Done! \n');

% Displaying results
disp('------------------------------------------------------------------');
disp('The optimal point location for the L1-norm case is: ');
disp(x1);
disp('The optimal point location for the L2-norm case is: ');
disp(x2);
Minimizing the L1-norm of the sum of the distances to fixed points... 
Calling SeDuMi: 46 variables (2 free), 22 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 = 22, order n = 49, dim = 49, blocks = 1
nnz(A) = 88 + 0, nnz(ADA) = 242, nnz(L) = 132
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            7.19E+001 0.000
  1 :  7.88E+000 1.87E+001 0.000 0.2598 0.9000 0.9000   2.59  1  1  1.0E+000
  2 :  1.19E+001 4.29E+000 0.000 0.2297 0.9000 0.9000   1.15  1  1  2.9E-001
  3 :  1.34E+001 8.96E-001 0.000 0.2087 0.9000 0.9000   1.02  1  1  6.7E-002
  4 :  1.37E+001 2.54E-001 0.000 0.2835 0.9000 0.9000   1.00  1  1  1.9E-002
  5 :  1.39E+001 1.55E-002 0.000 0.0611 0.9900 0.9900   1.00  1  1  1.2E-003
  6 :  1.39E+001 8.05E-007 0.209 0.0001 1.0000 1.0000   1.00  1  1  
iter seconds digits       c*x               b*y
  6      0.0   Inf  1.3868099974e+001  1.3868099974e+001
|Ax-b| =  1.4e-015, [Ay-c]_+ =  2.7E-016, |x|= 5.6e+000, |y|= 4.5e+000

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    0.000E+000    0.000E+000    
Max-norms: ||b||=2.183186e+000, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +13.8681
Done! 
Minimizing the L2-norm of the sum of the distances to fixed points... 
Calling SeDuMi: 35 variables (2 free), 22 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 = 22, order n = 27, dim = 38, blocks = 12
nnz(A) = 66 + 0, nnz(ADA) = 264, nnz(L) = 208
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.04E+001 0.000
  1 :  9.28E+000 6.74E+000 0.000 0.3301 0.9000 0.9000   2.25  1  1  1.1E+000
  2 :  1.08E+001 1.38E+000 0.000 0.2040 0.9000 0.9000   1.30  1  1  2.3E-001
  3 :  1.14E+001 1.08E-001 0.000 0.0788 0.9900 0.9900   1.04  1  1  1.8E-002
  4 :  1.15E+001 7.38E-003 0.000 0.0681 0.9900 0.9900   1.00  1  1  1.3E-003
  5 :  1.15E+001 3.90E-004 0.000 0.0529 0.9900 0.9900   1.00  1  1  6.7E-005
  6 :  1.15E+001 6.24E-005 0.000 0.1598 0.9073 0.9000   1.00  1  1  1.1E-005
  7 :  1.15E+001 7.13E-006 0.212 0.1144 0.9455 0.9450   1.00  1  1  1.3E-006
  8 :  1.15E+001 1.58E-006 0.000 0.2221 0.9036 0.9000   1.00  1  1  2.9E-007
  9 :  1.15E+001 2.61E-007 0.000 0.1645 0.9058 0.9000   1.00  2  2  5.1E-008
 10 :  1.15E+001 4.14E-008 0.000 0.1587 0.9055 0.9000   1.00  2  2  9.1E-009

iter seconds digits       c*x               b*y
 10      0.1   8.3  1.1483929305e+001  1.1483929241e+001
|Ax-b| =  2.6e-009, [Ay-c]_+ =  1.3E-009, |x|= 6.9e+000, |y|= 3.3e+000

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    6.009E-002    0.000E+000    
Max-norms: ||b||=2.183186e+000, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 83.9825.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +11.4839
Done! 
------------------------------------------------------------------
The optimal point location for the L1-norm case is: 
   -0.0956
    0.1139

The optimal point location for the L2-norm case is: 
    0.1251
    0.1716