% OBJECTIVE FUNCTION
f = @(x) 20 + x(:,1).^2 + x(:,2).^2 - 10*cos(2*pi*x(:,1)) - 10*cos(2*pi*x(:,2))

% OPTIMIZATION SETTINGS
o = struct	% initializing struct
o.d = 2	% dimension of decision variable
o.lb = -5.12	% lower bounds
o.ub = 5.12	% upper bounds

% GRAPHIC REPRESENTATION
[x,y] = meshgrid(o.lb:0.2:o.ub)
surf(x,y,f([x(:),y(:)]))

% ALGORITHM OPTIONS

o.maxit = 29	% number of iterations 

% OPTIMIZATION 
rng(0)	% for tractability 
[xmin,fmin,popPos,popCost] = ga(f,o)	% running minimization  

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% [~,~,~,~,info] = ga(f,o)
% info.sol = [0 0 0]	% solution 
% info.animate = true	% plot animation 
% info.animfreq = 3	% frame frequency 
% info.np = 21	% number of points for meshgrid 
% optimview('ga',info)