% Demo showing effect of positive definite or indefinite Hessians

 x = linspace(-2,2);
 y = linspace(-2,2);

 [X,Y] = meshgrid(x,y);
 a = .5;
 b = .5;  % increase this parameter
 b = 8;  % increase this parameter
 c =  2;

 F = a*X.^2 + b*Y.^2 + c*X.*Y;

 figure(1), clf
 surf(X,Y,F) 
 xlabel('$x$','fontsize',16,'interpreter','latex') 
 ylabel('$y$','fontsize',16,'interpreter','latex') 
 zlabel('$f(x,y)$','fontsize',16,'interpreter','latex') 
 colorbar

 A = [2*a c; c 2*b];
 [V,D] = eig(A)

 figure(2), clf
 pcolor(X,Y,F)
 xlabel('$x$','fontsize',16,'interpreter','latex') 
 ylabel('$y$','fontsize',16,'interpreter','latex') 
 shading interp
 colorbar
 hold on

 v = .5*D(1,1)*V(:,1);
 col='k'; if D(1,1)<0, col='w'; end 
 plot([0 v(1)],[0 v(2)],'-','linewidth',3,'color',col)
 v = .5*D(2,2)*V(:,2);
 col='k'; if D(2,2)<0, col='w'; end 
 plot([0 v(1)],[0 v(2)],'-','linewidth',3,'color',col)

 

