% OBJECTIVE FUNCTION
f = @(x)  (1.5 - x(:,1) + x(:,1).*x(:,2)).^2 + ...
       (2.25 - x(:,1) + x(:,1).*x(:,2).^2).^2 + ...
       (2.625 - x(:,1) + x(:,1).*x(:,2).^3).^2

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

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

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

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