clf
f=@(x,y) x.^4/4-x.^2/2+y.^2/2;

v = -2:0.1:2;
[X,Y] = meshgrid(v);
Z=f(X,Y);
%contour(v,v,Z,40), X

L=linspace(-1,3,10);
[C,h] = contour(X,Y,Z,L);
%set(h,'ShowText','on','TextStep',get(h,'LevelStep'))
axis square, hold on

% This piece of code (if uncommented), plots the gradient field.

% vg=-2:0.5:2;
% [X,Y]=meshgrid(vg);
% Z=f(X,Y);
% [px,py] =  gradient(Z,.2,.2);
% quiver(vg,vg,-px,-py), hold off