% 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(-1.5,1.5,120);
x2 = linspace(-.5,1.5,120);
[X,Y]=meshgrid(x1,x2);
Fvec = vectorize(inline('100*(y-x*x)^2 + (1-x)^2','x','y'));
F = Fvec(X,Y);
v = [300,200,100,60,30,20,10,5,3,2,1,.1];
[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('100*(x(2)-x(1)*x(1))^2 + (1-x(1))^2'),xguess,...
         options)
