%% Plot Vectors Normal to Surface
% Plot vectors that are normal to the surface defined by the function z = xe^{-x^2-y^2}. Use the quiver3 function to plot the vectors and the surf function to plot the surface.
% First, create a grid of x- and y-values that are equally spaced. Use them to calculate z. Then, find the normal vectors.

[X,Y] = meshgrid(-2:0.25:2,-1:0.2:1);
Z = X.*exp(-X.^2 - Y.^2);
[U,V,W] = surfnorm(X,Y,Z);

% Display the vectors as a 3-D quiver plot. Then, display the surface in the same axes. Adjust the display so that the vectors appear normal to the surface by calling axis equal.

quiver3(X,Y,Z,U,V,W)
hold on
surf(X,Y,Z)
axis equal

% Copyright 2020 The MathWorks, Inc.