%% Contour Plot of Vector Field
% Calculate the 2-D gradient of x e^{-x^2-y^2} on a grid.

x = -2:0.2:2;
y = x';
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z);

%
% Plot the contour lines and vectors in the same figure.

figure
contour(x,y,z)
hold on
quiver(x,y,px,py)
hold off

% Copyright 2012 The MathWorks, Inc.