%% 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 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)

% Copyright 2012 The MathWorks, Inc.