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

    %% Laplacian of Multivariate Function
% Calculate and plot the discrete Laplacian of a multivariate function.
%%
% Define the x and y domain of the function.

% Copyright 2015 The MathWorks, Inc.

[x,y] = meshgrid(-5:0.25:5,-5:0.25:5);
%%
% Define the function $U(x,y) = \frac{1}{3} \left( x^4 + y^4 \right)$ over
% this domain.
U = 1/3.*(x.^4+y.^4);
%%
% Calculate the Laplacian of this function using |del2|. The spacing
% between the points in |U| is equal in all directions, so you can specify
% a single spacing input, |h|.
h = 0.25;
L = 4*del2(U,h);
%%
% Analytically, the Laplacian of this function is equal to $\Delta U(x,y) =
% 4x^2 + 4y^2$.
%%
% Plot the discrete Laplacian, |L|.
figure
surf(x,y,L)
grid on
title('Plot of $\Delta U(x,y) = 4x^2+4y^2$','Interpreter','latex')
xlabel('x')
ylabel('y')
zlabel('z')
view(35,14)
%%
% The graph of |L| agrees with the analytic result for the Laplacian.