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

% OPTIMIZATION SETTINGS
o = struct	% initializing struct
o.lb = -50	% lower bounds
o.ub = 50	% upper bounds

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

% OPTIMIZATION 
rng(0)	% for tractability 
x0 = [45,45]	% initial guess 
[xmin,fmin,info] = fminsearch(f,x0,o)	% running minimization  

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% x0 = [45,45]
% [~,~,info] = fminsearch(f,x0,o)
% info.sol = [0 0 0]	% solution 
% info.animate = true	% plot animation 
% info.animfreq = 5	% frame frequency 
% optimview('fminsearch',info)