function sixmin = sixhumps
%   SIXHUMPS Plots function and returns function handle to six humps function.

%   Copyright 2014 The MathWorks, Inc.

[X,Y] = meshgrid(-2:.1:2,-1:.05:1);
Z = 4*X.^2 - 2.1*X.^4 + X.^6./3 + X.*Y - 4*Y.^2 + 4*Y.^4;
surf(X,Y,Z);view(-44,14)
xlabel('x');ylabel('y')
title('Six-hump camelback function')
figure
possColors = 'kbgcrm';
sixmin = @(x)(4*x(:,1).^2 - 2.1*x(:,1).^4 + x(:,1).^6/3 ...
    + x(:,1).*x(:,2) - 4*x(:,2).^2 + 4*x(:,2).^4);
f = @(x,y)sixmin([x,y]); % vectorized objective fcn
ezcontour(f,[-2 2 -1.1 1.1])
xsolution =    [0.0898   -0.7127
   -0.0898    0.7127
   -1.7036    0.7961
    1.7036   -0.7961
    1.6071    0.5687
   -1.6071   -0.5687];
hold on
for i = 1:size(xsolution,1)
    cIdx = rem(i-1, length(possColors)) + 1;
    color = possColors(cIdx);
    plot(xsolution(i,1),xsolution(i,2),'*','Color',...
        color,'MarkerSize',25); % plot center of basin with *
end
xlabel x
ylabel y
title('Six-hump camelback function')
hold off