function fig1

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

z = flipud(x).^2 - 2*x + repmat([-1;1], 1, size(x,2));

figure; hold on;
plotdata(z, y);

plot(0.5 * ones(1,2), [-3.5,5.5], 'k-');

axis([-3.5, 3.5, -3.5, 5.5]);
axis('square');
grid on;

for n = 1:size(x,2)-2;
	text(z(1,n)+0.1, z(2,n)+0.1, [num2str(n)]);
end;
n = size(x,2)-1;
text(z(1,n)+0.1, z(2,n)+0.1, [num2str(n) ',' num2str(n+1)]);


h = text(-1.65, 1, '+'); set(h, 'fontsize', 40);
h = text( 2.05, 1, '-'); set(h, 'fontsize', 40);

legend('y = +1', 'y = -1', 'boundary');
xlabel('z1'); ylabel('z2');


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

x2 = -2.5:0.1:2.5;
x1 = (x2.^2 - 1.5)/2;
plot(x1, x2, 'k-');

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

for n = 1:size(x,2)
	text(x(1,n)+0.1, x(2,n)+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');


% quadprog
n = size(z, 2);
A = -([z; -ones(1,n)] .* repmat(y, 3, 1))';
b = -ones(n, 1);
H = eye(3); H(3,3) = 0;
f = zeros(3, 1);
[wt,lam] = qp(H, f, A, b)