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

    %% Laplacian of Natural Logarithm Function
% Calculate the discrete Laplacian of a natural logarithm function.
%%
% Define the x and y domain of the function on a grid of real numbers.

% Copyright 2015 The MathWorks, Inc.

[x,y] = meshgrid(-5:5,-5:0.5:5);
%%
% Define the function $U(x,y) = \frac{1}{2} \log\left(x^2y\right)$ over
% this domain.
U = 0.5*log(x.^2.*y);
%%
% The logarithm is complex-valued when the argument |y| is negative.
%%
% Use |del2| to calculate the discrete Laplacian of this function. Specify
% the spacing between grid points in each direction.
hx = 1; 
hy = 0.5;
L = 4*del2(U,hx,hy);
%%
% Analytically, the Laplacian is equal to $\Delta U(x,y) = - \left(
% 1/x^2+1/2y^2 \right)$. This function is not defined on
% the lines $x = 0$ or $y = 0$.
%%
% Plot the real parts of |U| and |L| on the same graph.
figure
surf(x,y,real(L))
hold on
surf(x,y,real(U))
grid on
title('Plot of U(x,y) and $\Delta$ U(x,y)','Interpreter','latex')
xlabel('x')
ylabel('y')
zlabel('z')
view(41,58)
%%
% The top surface is |U| and the bottom surface is |L|.