%% Show Gradient with Quiver Plot
% Plot the gradient of the function $z = xe^{-x^2-y^2}$.

% Copyright 2015 The MathWorks, Inc.


[X,Y] = meshgrid(-2:.2:2);
Z = X.*exp(-X.^2 - Y.^2);
[DX,DY] = gradient(Z,.2,.2);

figure
contour(X,Y,Z)
hold on
quiver(X,Y,DX,DY)
hold off