% Example of nonconvex optmization in which the convex combination of
% one-variable-at-a-time optimizations is not decreasing.
nxy = 221;
xvec = linspace(-0.5, 5, nxy);
yvec = linspace(-0.5, 5, nxy);
ncont = 15;
[xgrid, ygrid] = meshgrid(xvec, yvec);
Vgrid = V(xgrid, ygrid);
% choose initial point and find the two one variable at a time
% minimizers.
x0 = 0;
y0 = 0;
xguess = 2.5;
yguess = 2.5;
xp = fminsearch(@(x) V(x, y0), xguess);
yp = fminsearch(@(y) V(x0, y), yguess);
xw = (x0 + xp)/2;
yw = (y0 + yp)/2;
figure();
hold('on');
c = contour(xvec, yvec, Vgrid, ncont);
plot(x0, x0, 'ok', xp, y0, '+k', x0, yp, '+k', xw, yw, 'ok', ...
[xp, x0], [y0, yp], '-k', [x0, xw], [x0, yw], '-k')