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

    %% Plot Surface
% Create a 2-D grid with uniformily spaced _x_-coordinates and _y_-coordinates
% in the interval [-2,2].
x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x);

%%
% Evaluate and plot the function $f(x,y) = xe^{-x^2-y^2}$ over the 2-D
% grid.
F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F)

%%
% Starting in R2016b, it is not always necessary to create the grid before
% operating over it. For example, computing the expression $xe^{-x^2-y^2}$
% implicitly expands the vectors |x| and |y|. For more information on
% implicit expansion, see <docid:matlab_prog.btyv9yp-1>.
surf(x,y,x.*exp(-x.^2-(y').^2))