www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/EvaluateFunctionOverGriddedDomainExample.m

    %% Evaluate Function Over Gridded Domain
% 
%%
% Evaluate 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.

% Copyright 2015 The MathWorks, Inc.

[X1,X2] = ndgrid(-2:.2:2, -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)