# laplacian

Laplacian of symbolic field

## Syntax

``l = laplacian(f,v)``
``l = laplacian(f)``

## Description

example

````l = laplacian(f,v)` returns the Laplacian of the symbolic field `f` with respect to the vector `v` in Cartesian coordinates. If `f` is an array, then the function computes the Laplacian for each element of `f` and returns the output `l` that is the same size as `f`.```

example

````l = laplacian(f)` returns the Laplacian of the symbolic field `f` with respect to a default vector constructed from the symbolic variables in `f`.```

## Examples

collapse all

Create a symbolic function for the scalar field $\mathit{f}\left(\mathit{x},\mathit{y},\mathit{z}\right)=\mathrm{sin}\left(\mathit{x}\right)+{\mathit{y}}^{2}+{\mathit{z}}^{3}$. Compute the Laplacian of this function with respect to the vector $\left(\mathit{x},\mathit{y},\mathit{z}\right)$.

```syms x y z f(x,y,z) = sin(x) + y^2 + z^3; v = [x y z]; lf = laplacian(f,v)```
`lf(x, y, z) = $6 z-\mathrm{sin}\left(x\right)+2$`

Create another scalar field $\mathit{g}\left(\mathit{x},\mathit{y},\mathit{z}\right)={\mathit{x}}^{2}\mathit{y}+\mathit{z}$. Find the Laplacian without specifying the vector to differentiate with. Because `g` is a function of symbolic scalar variables, `laplacian` finds the Laplacian of `g` with respect to the default variables as defined by `symvar(g)`.

```g(x,y,z) = x^2*y + z; lg = laplacian(g)```
`lg(x, y, z) = $2 y$`

Since R2023a

Create a symbolic vector field $\mathit{F}=\left[\begin{array}{c}\mathrm{sin}\left(\mathit{x}\right)+{\mathit{y}}^{2}+{\mathit{z}}^{3}\\ {\mathit{x}}^{2}\mathit{y}+{\mathit{z}}^{2}\end{array}\right]$. Find the Laplacian of this vector field with respect to $\left(\mathit{x},\mathit{y},\mathit{z}\right)$.

```syms x y z F = [sin(x) + y^2 + z^3; x^2*y + z]; v = [x y z]; l = laplacian(F,v)```
```l =  $\left(\begin{array}{c}6 z-\mathrm{sin}\left(x\right)+2\\ 2 y\end{array}\right)$```

Since R2023a

Create a 3-by-1 vector as a symbolic matrix variable $\mathbit{X}$. Create a scalar field that is a function of $\mathbit{X}$ as a symbolic matrix function $\psi \left(\mathbit{X}\right)$, keeping the existing definition of $\mathbit{X}$.

```syms X [3 1] matrix syms psi(X) [1 1] matrix keepargs```

Show that the divergence of the gradient of $\psi \left(\mathbit{X}\right)$ is equal to the Laplacian of $\psi \left(\mathbit{X}\right)$, that is ${\nabla }_{\mathit{X}}\cdot {\nabla }_{\mathit{X}}\text{\hspace{0.17em}}\psi \left(\mathbit{X}\right)={\Delta }_{\mathit{X}}\psi \left(\mathbit{X}\right)$.

`divOfGradPsi = divergence(gradient(psi,X),X)`
`divOfGradPsi(X) = `
`lapPsi = laplacian(psi,X)`
`lapPsi(X) = `

Create a vector field that is a function of $\mathbit{X}$ as a symbolic matrix function $\mathbit{A}\left(\mathbit{X}\right)$.

`syms A(X) [3 1] matrix keepargs`

Show that the gradient of the divergence of $\mathbit{A}\left(\mathbit{X}\right)$ minus the curl of the curl of $\mathbit{A}\left(\mathbit{X}\right)$ is equal to the Laplacian of $\mathbit{A}\left(\mathbit{X}\right)$, that is ${\nabla }_{\mathbit{X}}{\nabla }_{\mathbit{X}}\cdot \mathbit{A}\left(\mathbit{X}\right)-{\nabla }_{\mathbit{X}}×{\nabla }_{\mathbit{X}}×\mathbit{A}\left(\mathbit{X}\right)={\Delta }_{\mathbit{X}}\mathbit{A}\left(\mathbit{X}\right)$.

`identityA = gradient(divergence(A,X),X) - curl(curl(A,X),X)`
`identityA(X) = `

## Input Arguments

collapse all

Symbolic field, specified as a symbolic expression, symbolic function, symbolic matrix variable, or symbolic matrix function. The input field can be a scalar, vector, matrix, or a multidimensional array, where the Laplacian is computed for each element in the input.

• If `f` is a function of symbolic scalar variables, where `f` is of type `sym` or `symfun`, then the vector `v` must be of type `sym` or `symfun`.

• If `f` is a function of symbolic matrix variables, where `f` is of type `symmatrix` or `symfunmatrix`, then the vector `v` must be of type `symmatrix` or `symfunmatrix`.

Data Types: `sym` | `symfun` | `symmatrix` | `symfunmatrix`

Vector with respect to which you find the Laplacian, specified as a vector of symbolic scalar variables, symbolic function, symbolic matrix variable, or a symbolic matrix function.

• If you do not specify `v` and `f` is a function of symbolic scalar variables, then, by default, `laplacian` constructs vector `v` from the symbolic scalar variables in `f` with the order of variables as defined by `symvar(f)`.

• If `v` is a symbolic matrix variable of type `symmatrix`, then `v` must have a size of `1`-by-`N` or `N`-by-`1`.

• If `v` is scalar, then ```laplacian(f,v) = diff(f,2,v)```.

Data Types: `sym` | `symfun` | `symmatrix` | `symfunmatrix`

## Limitations

• Symbolic Math Toolbox™ currently does not support the `dot` or `cross` functions for symbolic matrix variables and functions of type `symmatrix` and `symfunmatrix`. If vector calculus identities involve dot or cross products, then the toolbox displays those identities in terms of other supported functions instead. To see a list of all the functions that support symbolic matrix variables and functions, use the commands `methods symmatrix` and `methods symfunmatrix`.

• If the input data type of the symbolic field `f` is `symmatrix` or `symfunmatrix`, then `laplacian` does not evaluate the partial derivatives of `f`. Instead, it returns an unevaluated formula for symbolic manipulation and formula rearrangement.

collapse all

### Laplacian

The Laplacian or Laplace's differential operator of the scalar field f with respect to the vector x = (x1,...,xn) is the sum of the second derivatives of f with respect to x1,...,xn.

`${\Delta }_{x}f=\sum _{i=1}^{n}\frac{{\partial }^{2}f}{\partial {x}_{i}^{2}}$`

If f is a vector field or a tensor field (multidimensional array), then the Laplacian operator is applied to each element in f.

## Alternatives

The Laplacian of a scalar function or functional expression is the divergence of the gradient of that function or expression.

`$\Delta f=\nabla \cdot \left(\nabla f\right)$`

For a symbolic scalar field `f`, you can also compute the Laplacian using the `divergence` and `gradient` functions.

```syms f(x,y) divergence(gradient(f(x,y)),[x y])```

## Version History

Introduced in R2012a

expand all