function prob52

M = 2;

x = [1     0     0    -1     0     0    -2; ...
     0     1    -1     0     2    -2     0]';
y = [-1   -1     -1     1     1     1     1]';

n = size(x, 1);

K = (1 + x * x').^M;
yyK = (y * y') .* K;

lm = quadprog(yyK, -ones(n,1), [], [], y', 0, zeros(1,n), 999*ones(1,n));
lm(find(lm < 1e-8)) = 0;
disp('lambda = ');
disp(lm')

VCs = find(lm > 0);
[dist, t] = vcm(x, x(VCs,:), y(VCs), lm(VCs), M)

figure; hold on;
plotdata(x', y'); grid on;

vcmbound([1,0], 6, 0, 360, x(VCs,:), y(VCs), lm(VCs), M, t);

axis([-2.5, 3, -2.5, 2.5]);
axis('square');
grid on;

for n = 1:size(x,1)
	text(x(n,1)+0.1, x(n,2)+0.1, [num2str(n)]);
end;
h = text(-1.65, 0.5, '+'); set(h, 'fontsize', 40);
h = text( 0.35, 0.5, '-'); set(h, 'fontsize', 40);

legend('y = +1', 'y = -1', 'boundary');
xlabel('x1'); ylabel('x2');



return;
z = [x.^2, ones(n, 1), sqrt(2) * x, sqrt(2) * x(:,1).*x(:,2)];
m = size(z, 2)+1;
A = -[z, -ones(n,1)] .* repmat(y, 1, m);
b = -ones(n, 1);
H = eye(m); H(m,m) = 0;
f = zeros(m, 1);
[wt,lam] = qp(H, f, A, b)
disp('distances are ')
disp((y .* ([z, -ones(n,1)] * wt))');
