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

% OPTIMIZATION SETTINGS
o = struct	% initializing struct
o.lb = 1	% lower bounds
o.ub = 5	% upper bounds

% GRAPHIC REPRESENTATION
[x,y] = meshgrid(1:0.2:5)
surf(x,y,f([x(:),y(:)]))

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

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% x0 = [2.1,3]
% [~,~,info] = fminsearch(f,x0,o)
% info.sol = [pi pi -1]	% solution 
% info.animate = true	% plot animation 
% info.animfreq = 6	% frame frequency 
% info.np = 20	% number of points for meshgrid 
% optimview('fminsearch',info)