Laplacian: laplacian

### 6.21.2 Laplacian: laplacian

Recall, the Laplacian of a function F of n variables x1,…,xn is

∇2(F)= |
∂2 F
∂ x12
| + |
∂2 F
∂ x22
| + ⋯+ |
∂2 F
∂ xn2

Also, the n× n discrete Laplacian matrix (also called the second difference matrix) is the n × n tridiagonal matrix with 2s on the main diagonal, −1s just above and below the main diagonal;

⎛ ⎜ ⎜ ⎜ ⎜ ⎜ ⎝ |
2 | −1 | 0 | ⋯ | 0
−1 | 2 | −1 | ⋯ | 0
⋮ | ⋮ | ⋮ | ⋮ | 0
0 | ⋯ | −1 | 2 | −1
0 | ⋯ | 0 | −1 | 2
| ⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠

If L is the n× n discrete Laplacian matrix and Y is an n × 1 column vector whose kth coordinate is yi = y(a + kΔ x) for a twice differential function y, then the kth coordinate of L Y will be −y(a + (k−1)Δ x) + 2 y(a + kΔ x) − y (a + (k−1)Δ x) (implicitly assuming that y(a) = y(a + (N+1)Δ x) = 0), which approximates y″(a + kΔ x). So L Y is approximately −Δ x2 Y″, where Y″ is the n × 1 column vector whose kth coordinate is y″(a + kδ x).

The laplacian command can compute the Laplacian operator or the discrete Laplacian matrix.

To compute the Laplacian operator:

- laplacian takes two arguments:
  - expr, an expression involving several variables.
  - vars, a list of the variable names.
- laplacian(expr,vars) returns the Laplacian of the expression.

Example
Find the Laplacian of F(x,y,z)=2x2y−xz3.
Input:

laplacian(2*x^2*y-x*z^3,[x,y,z])

Output:

−6 x z+4 y

To compute the discrete Laplacian matrix:

- laplacian takes one argument:
  n, an integer or floating-point integer.
- laplacian(n) returns the n× n discrete Laplacian matrix.

Examples.

- Input:
  laplacian(3)
  Output:

  ⎡ ⎢ ⎢ ⎣ |
  2 | −1 | 0
  −1 | 2 | −1
  0 | −1 | 2
  | ⎤ ⎥ ⎥ ⎦

- Input:
  laplacian(2.0)
  Output:

  ⎡ ⎢ ⎣ |
  2.0 | −1.0
  −1.0 | 2.0
  | ⎤ ⎥ ⎦