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

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

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

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

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% x0 = [-0.2,1.2]
% [~,~,info] = fminsearch(f,x0,o)
% info.sol = [2 0.10578 -2.02181]	% solution 
% info.animate = true	% plot animation 
% info.animfreq = 5	% frame frequency 
% info.np = 16	% number of points for meshgrid 
% optimview('fminsearch',info)