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: 68 variables (2 free), 44 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 = 44, order n = 49, dim = 82, blocks = 23
nnz(A) = 99 + 0, nnz(ADA) = 352, nnz(L) = 263
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            7.09E+000 0.000
  1 :  5.29E+000 2.45E+000 0.000 0.3455 0.9000 0.9000   2.07  1  1  1.9E+000
  2 :  1.13E+001 8.70E-001 0.000 0.3549 0.9000 0.9000   0.71  1  1  8.1E-001
  3 :  1.50E+001 2.10E-001 0.000 0.2411 0.9000 0.9000   0.83  1  1  2.1E-001
  4 :  1.65E+001 1.88E-002 0.000 0.0895 0.9900 0.9900   0.93  1  1  2.0E-002
  5 :  1.67E+001 1.39E-003 0.000 0.0738 0.9900 0.9900   1.00  1  1  1.5E-003
  6 :  1.67E+001 2.37E-005 0.000 0.0171 0.9900 0.9900   1.00  1  1  3.0E-005
  7 :  1.67E+001 2.32E-008 0.406 0.0010 0.9900 0.9776   1.00  1  1  1.2E-006
  8 :  1.67E+001 1.24E-009 0.106 0.0534 0.9900 0.9903   1.00  1  1  6.0E-008
  9 :  1.67E+001 2.62E-010 0.000 0.2117 0.9000 0.8018   1.00  2  2  1.3E-008

iter seconds digits       c*x               b*y
  9      0.1   Inf  1.6683118539e+001  1.6683118616e+001
|Ax-b| =  6.3e-008, [Ay-c]_+ =  1.1E-011, |x|= 1.3e+001, |y|= 1.4e+001

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|| = 2.19573.
------------------------------------------------------------------------
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!