clear all; clc;
%%
n = 2;
k = 10;
X = randn(n, k);

cvx_begin
    variable x(n)
    variable r(1)
    minimize r
    subject to
        for i = 1 : k
            norm(x-X(:, i), 2) <= r;
        end
cvx_end

%% If 2-D, make a plot
if n == 2
    clf; hold all; xlim([-4, 4]); ylim([-4, 4]);
    plot(X(1, :), X(2, :), 'k.', 'MarkerSize', 10);
    axis equal;
    drawnow;
    pause(3);
    plot(x(1), x(2), 'r.', 'MarkerSize', 15);
    t = linspace(0, 2*pi, 251);
    plot(x(1)+r*cos(t), x(2)+r*sin(t), 'k-');
    title(sprintf('Optimal radius: %g', r))
end
