%% Run |GlobalSearch| on Multidimensional Problem
% Create an optimization problem that has several local minima, and try to find 
% the global minimum using |GlobalSearch|. The objective is the six-hump camel 
% back problem (see <docid:gads.bsc599n Run the Solver>).

rng default % For reproducibility
gs = GlobalSearch;
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);
problem = createOptimProblem('fmincon','x0',[-1,2],...
    'objective',sixmin,'lb',[-3,-3],'ub',[3,3]);
x = run(gs,problem)
%% 
% You can request the objective function value at |x| when you call |run| 
% by using the following syntax:
% 
% |[x,fval] = run(gs,problem)|
% 
% However, if you neglected to request |fval|, you can still compute the 
% objective function value at |x|.

fval = sixmin(x)
%%
[X,Y]=meshgrid(-2:.2: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('sixmin(x,y)')
% Six-hump camel back.

%% 
% _Copyright 2012 The MathWorks, Inc._