% Plots contours of Rosenbrock's function 
% near the minimum at (1,1).

x = -1:.005:1.5;
y = -1:.005:1.5;
[X,Y] = meshgrid(x,y);

Z = 100.*(Y-X.^2).^2 + (1-X).^2;

% Plot contours with unequal vertical spacing:
t = 0:1/40:1;
p = (1-t)*(1.02) + t*1.5;
q = (1-t)*(1.02) + t*(-1);
v = 100.*(q-p.^2).^2 + (1-p).^2;
contour(X,Y,Z,v)
colormap(hsv(128*128))
title('Rosenbrock''s Function')
hold on

% Plot minimum:
plot(1, 1, 'ok', 'LineWidth', 2, 'MarkerSize', 5, 'MarkerFaceColor', 'w')

% Format
axis square

clear x y X Y Z t p q v