function rbhess(n)

% Plots Rosenbrock's function with a colormap 
% indicating local determinant of the hessian.
%
% Magnitudes of -n and below are mapped to the  
% lowest color in the colormap and magnitudes of  
% n and above are mapped to the highest color in
% the colormap.
%
% For small n, decrease the step size on x and y.

x = -2:0.01:2;
y = -1:0.01:3;
[X, Y] = meshgrid(x, y);

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

% Analytic hessian and determinant:
h11 = 1200*X.^2 - 400*Y + 2*ones(size(X));
h12 = -400*X;
h21 = -400*X;
h22 = 200*ones(size(X));
D = h11.*h22 - h21.*h12;

% Plot:
surf(X, Y, Z, D)
shading interp
set(gca, 'clim', [-n, n])
colorbar
title('Rosenbrock''s Function: Hessian Determinants')

clear x y X Y Z h11 h12 h21 h22 D