%% Evaluate Function Over Gridded Domain
% Evaluate and plot the function
% x_1 e^{-x_1^2-x_2^2}
% over the gridded domain
% -2<x_1<2 and -2<x_2<2.
%
% Create a grid of values for the domain.

[X1,X2] = ndgrid(-2:.2:2);

%
% Evaluate the function over the domain.

Z = X1 .* exp(-X1.^2 - X2.^2);

%
% Generate a mesh plot of the function.

mesh(X1,X2,Z)

%
%  In R2016b and later releases, this task does not require the use of ndgrid. Instead, you can construct the grid using implicit expansion with these commands:
% x = -2:.2:2;
% Z1 = x.' .* exp(-(x.').^2 - x.^2);
% Copyright 2012 The MathWorks, Inc.