% Finds minimum of Rosenbrock's function
%using fmins from matlab library.
%first look at the function in  a contour plot
clear
close all
clc
x1 = linspace(-3,3,120);
x2 = linspace(-3,3,120);
[X,Y]=meshgrid(x1,x2);
Fvec = vectorize(inline('x*y*exp(-(x^2+y^2))','x','y'));
F = Fvec(X,Y);
v = [0.01 0.03 0.06 0.09 0.13 -0.01 -0.03 -0.06 -0.09 -0.13];
[C,h]=contour(X,Y,F,v);
clabel(C,h);
%clabel (C,'manual');
pause
tol=1.E-8;
xguess = input('enter x1,x2 as row vector guess')
options = optimset ('display', 'Iter', 'TolX', tol);
[XMIN Fmin] = fminsearch(inline('x(1)*x(1)*exp(-(x(1)^2+x(2)^2))'),xguess,...
         options)
