One free point localization

% Section 8.7.3, Boyd & Vandenberghe "Convex Optimization"
% Joelle Skaf - 10/24/05
%
% K fixed points x_1,...,x_K in R^2 are given and the goal is to place
% one additional point x such that the sum of the squares of the
% Euclidean distances to fixed points is minimized:
%           minimize    sum_{i=1}^K  ||x - x_i||^2
% The optimal point is the average of the given fixed points

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

% minimizing the sum of Euclidean distance
fprintf(1,'Minimizing the sum of the squares the distances to fixed points...');

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

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

% Displaying results
disp('------------------------------------------------------------------');
disp('The optimal point location is: ');
disp(x);
disp('The average location of the fixed points is');
disp(sum(P,2)/K);
disp('They are the same as expected!');
Minimizing the sum of the squares the distances to fixed points... 
Calling sedumi: 77 variables, 35 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 = 35, order n = 56, dim = 89, blocks = 23
nnz(A) = 77 + 0, nnz(ADA) = 169, nnz(L) = 102
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.57E+00 0.000
  1 :  -1.55E+00 8.66E-01 0.000 0.3370 0.9000 0.9000   2.56  1  1  2.2E+00
  2 :  -7.67E+00 3.21E-01 0.000 0.3707 0.9000 0.9000   0.75  1  1  6.2E-01
  3 :  -1.28E+01 1.00E-01 0.000 0.3130 0.9000 0.9000   0.71  1  1  2.1E-01
  4 :  -1.54E+01 2.95E-02 0.000 0.2932 0.9000 0.9000   0.84  1  1  6.7E-02
  5 :  -1.66E+01 2.43E-03 0.000 0.0825 0.9900 0.9900   0.95  1  1  5.7E-03
  6 :  -1.66E+01 3.46E-05 0.293 0.0142 0.9000 0.0000   1.00  1  1  3.4E-03
  7 :  -1.66E+01 6.13E-06 0.000 0.1773 0.9151 0.9000   1.00  1  1  6.6E-04
  8 :  -1.67E+01 4.35E-08 0.161 0.0071 0.9990 0.9990   1.00  1  1  4.4E-06
  9 :  -1.67E+01 1.09E-08 0.093 0.2512 0.8840 0.9000   1.00  1  1  1.1E-06
 10 :  -1.67E+01 1.86E-09 0.028 0.1700 0.0000 0.9000   1.00  1  1  2.4E-07
 11 :  -1.67E+01 1.49E-10 0.000 0.0801 0.9900 0.9511   1.00  1  1  2.0E-08
 12 :  -1.67E+01 1.17E-11 0.309 0.0787 0.9900 0.9900   1.00  2  2  1.6E-09

iter seconds digits       c*x               b*y
 12      0.1   Inf -1.6683118749e+01 -1.6683118746e+01
|Ax-b| =   6.7e-10, [Ay-c]_+ =   3.1E-09, |x|=  1.7e+01, |y|=  8.3e+00

Detailed timing (sec)
   Pre          IPM          Post
0.000E+00    7.000E-02    0.000E+00    
Max-norms: ||b||=1, ||c|| = 3.848770e+00,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 4.39187.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +16.6831
Done! 
------------------------------------------------------------------
The optimal point location is: 
    0.0379
    0.0785

The average location of the fixed points is
    0.0379
    0.0785

They are the same as expected!