Quantcast

Documentation Center

  • Trial Software
  • Product Updates

del2

Discrete Laplacian

Syntax

Description

example

L = del2(U) returns a discrete approximation of Laplace's differential operator applied to U using the default spacing, h = 1, between all points.

example

L = del2(U,h) specifies a uniform, scalar spacing, h, between points in all dimensions of U.

example

L = del2(U,h1,...,hN) specifies the spacing, h1,...,hN, between points in each corresponding dimension of U. For each dimension, specify the spacing as a scalar or a vector of coordinates. The number of spacing inputs must equal the number of dimensions in U.

Examples

expand all

Second Derivative of Vector

Calculate the acceleration of an object from a vector of position data.

Create a vector of position data.

p = [1 3 6 10 16 18 29];

To find the acceleration of the object, use del2 to calculate the second numerical derivative of p. Use the default spacing h = 1 between data points.

L = 4*del2(p)
L =

     1     1     1     2    -4     9    22

Each value of L is an approximation of the instantaneous acceleration at that point.

Second Derivative of Cosine Vector

Calculate the discrete 1-D Laplacian of a cosine vector.

Define the domain of the function.

x = linspace(-2*pi,2*pi);

This produces 100 evenly spaced points in the range $-2\pi \le x \le 2\pi$ .

Create a vector of cosine values in this domain.

U = cos(x);

Calculate the Laplacian of U using del2. Use the domain vector x to define the 1-D coordinate of each point in U.

L = 4*del2(U,x);

Analytically, the Laplacian of this function is equal to $\Delta U = -\cos(x)$ .

Plot the results.

plot(x,U,x,L);legend('U(x)','L(x)','Location','Best')

The graph of U and L agrees with the analytic result for the Laplacian.

Laplacian of Multivariate Function

Calculate and plot the discrete Laplacian of a multivariate function.

Define the x and y domain of the function.

[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;hold on;grid on;
title('Plot of $\Delta U(x,y) = 4x^2+4y^2$','Interpreter','latex')
xlabel('x'); ylabel('y'); zlabel('z');
surf(x,y,L);
view(35,14)

The graph of L agrees with the analytic result for the Laplacian.

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.

[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;hold on;grid on;
title('Plot of U(x,y) and $\Delta$ U(x,y)','Interpreter','latex')
xlabel('x'); ylabel('y'); zlabel('z');
surf(x,y,real(L)); surf(x,y,real(U));
view(41,58)

The top surface is U and the bottom surface is L.

Input Arguments

expand all

U — Input arrayvector | matrix | multidimensional array

Input array, specified as a vector, matrix, or multidimensional array.

Data Types: single | double
Complex Number Support: Yes

h — Spacing in all dimensions1 (default) | scalar

Spacing in all dimensions, specified as 1 (default), or a scalar.

Data Types: single | double
Complex Number Support: Yes

h1,...,hN — Spacing in each dimensionscalars | vectors

Spacing in each dimension, specified as scalars or vectors. The number of spacing inputs must be equal to the number of dimensions in U. Each spacing input defines the spacing between points in the corresponding dimension of U:

  • Use a scalar to specify a uniform spacing.

  • Use a vector to specify a nonuniform spacing. The coordinate vector gives the position of each point and must have the same number of elements as the corresponding dimension of U (a one-to-one match of coordinates and points).

Data Types: single | double
Complex Number Support: Yes

Output Arguments

expand all

L — Discrete Laplacian approximationvector | matrix | multidimensional array

Discrete Laplacian approximation, returned as a vector, matrix, or multidimensional array. L is the same size as the input, U.

More About

expand all

Laplace's differential operator

If a matrix U is a function U(x,y) that is evaluated at the points of a square grid, then 4*del2(U) is a finite difference approximation of Laplace's differential operator applied to U,

For functions of more variables, U(x,y,z,...), the discrete Laplacian del2(U) calculates second-derivatives in each dimension,

where N is the number of dimensions in U and .

Algorithms

If the input U is a matrix, the interior points of L are found by taking the difference between a point in U and the average of its four neighbors:

Then, del2 calculates the values on the edges of L by linearly extrapolating the second differences from the interior. This formula is extended for multidimensional U.

See Also

|

Was this topic helpful?