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

% OPTIMIZATION SETTINGS
o = struct	% initializing struct
o.lb = [-1.5 -3]	% lower bounds
o.ub = 4	% upper bounds

% GRAPHIC REPRESENTATION
[x,y] = meshgrid(-1.5:0.5:4, -3:0.2:4)
surf(x,y,f([x(:),y(:)]))

% ALGORITHM OPTIONS

o.maxit = 40	% number of iterations 

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

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