# curl

Curl of symbolic vector field

## Syntax

``c = curl(V,X)``
``c = curl(V)``

## Description

example

````c = curl(V,X)` returns the curl of symbolic vector field `V` with respect to vector `X` in three-dimensional Cartesian coordinates. Both the vector field `V` and the vector `X` must be vectors with three components.```
````c = curl(V)` returns the curl of the vector field `V` with respect to a default vector constructed from the symbolic variables in `V`.```

## Examples

collapse all

Find the curl of the vector field $\mathit{V}\left(\mathit{x},\mathit{y},\mathit{z}\right)=\left({\mathit{x}}^{3}{\mathit{y}}^{2}\mathit{z},\text{\hspace{0.17em}}{\mathit{y}}^{3}{\mathit{z}}^{2}\mathit{x},\text{\hspace{0.17em}}{\mathit{z}}^{3}{\mathit{x}}^{2}\mathit{y}\right)$ with respect to vector $\mathit{X}=\left(\mathit{x},\mathit{y},\mathit{z}\right)$ in Cartesian coordinates.

```syms x y z V = [x^3*y^2*z, y^3*z^2*x, z^3*x^2*y]; X = [x y z]; c = curl(V,X)```
```c =  $\left(\begin{array}{c}{x}^{2} {z}^{3}-2 x {y}^{3} z\\ {x}^{3} {y}^{2}-2 x y {z}^{3}\\ {y}^{3} {z}^{2}-2 {x}^{3} y z\end{array}\right)$```

Find the curl of a 2-D vector field $\mathit{F}\left(\mathit{x},\mathit{y}\right)=\left(\mathrm{cos}\left(\mathit{x}+\mathit{y}\right),\mathrm{sin}\left(\mathit{x}-\mathit{y}\right),0\right)$. Plot the vector field as a quiver (velocity) plot and the $\mathit{z}$-component of its curl as a contour plot.

Create the 2-D vector field $\mathit{F}\left(\mathit{x},\mathit{y}\right)$ and find its curl. The curl is a vector with only the $\mathit{z}$-component.

```syms x y z F = [cos(x+y) sin(x-y) 0]; c = curl(F,[x,y,z])```
```c =  $\left(\begin{array}{c}0\\ 0\\ \mathrm{cos}\left(x-y\right)+\mathrm{sin}\left(x+y\right)\end{array}\right)$```

Plot the 2-D vector field $\mathit{F}\left(\mathit{x},\mathit{y}\right)$ for the region $-2<\mathit{x}<2$ and $-2<\mathit{y}<2$. MATLAB® provides the `quiver` plotting function for this task. The function does not accept symbolic arguments. First, replace symbolic variables in expressions for components of `F` with numeric values. Then use `quiver`.

```v = -2:0.1:2; [xPlot,yPlot] = meshgrid(v); Fx = subs(F(1),{x,y},{xPlot,yPlot}); Fy = subs(F(2),{x,y},{xPlot,yPlot}); quiver(xPlot,yPlot,Fx,Fy) hold on```

Next, plot the contour of the $\mathit{z}$-component of the curl using `contour`.

```cPlot = subs(c(3),{x,y},{xPlot,yPlot}); contour(xPlot,yPlot,cPlot,"ShowText","on") title("Contour Plot of Curl of 2-D Vector Field") xlabel("x") ylabel("y")```

Since R2023a

Derive the electromagnetic wave equation in free space without charge and without current sources from Maxwell's equations.

First, create symbolic scalar variables to represent the vacuum permeability and permittivity. Create a symbolic matrix variable to represent the Cartesian coordinates. Create two symbolic matrix functions to represent the electric and magnetic fields as functions of space and time.

```syms mu_0 epsilon_0 syms X [3 1] matrix syms E(X,t) B(X,t) [3 1] matrix keepargs```

Next, create four equations to represent Maxwell's equations.

`Maxwell1 = divergence(E,X) == 0`
`Maxwell1(X, t) = ${\nabla }_{X}·E\left(X,t\right)={\mathrm{0}}_{1,1}$`
`Maxwell2 = curl(E,X) == -diff(B,t)`
```Maxwell2(X, t) =  ```
`Maxwell3 = divergence(B,X) == 0`
`Maxwell3(X, t) = ${\nabla }_{X}·B\left(X,t\right)={\mathrm{0}}_{1,1}$`
`Maxwell4 = curl(B,X) == mu_0*epsilon_0*diff(E,t)`
```Maxwell4(X, t) =  ```

Then, find the wave equation for the electric field. Compute the curl of the second Maxwell equation.

`wave_E = curl(Maxwell2,X)`
```wave_E(X, t) =  ```

Substitute the first Maxwell equation in the electric field wave equation. Use `lhs` and `rhs` to obtain the left and right sides of the first Maxwell equation.

`wave_E = subs(wave_E,lhs(Maxwell1),rhs(Maxwell1))`
```wave_E(X, t) =  ```

Compute the time derivative of the fourth Maxwell equation.

`dMaxwell4 = diff(Maxwell4,t)`
```dMaxwell4(X, t) =  ```

Substitute the term that involves the magnetic field ${\nabla }_{\mathbit{X}}×\frac{\partial }{\partial \mathit{t}}\mathbit{B}\left(\mathbit{X},\mathit{t}\right)$ in `wave_E` with the right side of `dMaxwell4`. Use `lhs` and `rhs` to obtain these terms from `dMaxwell4`.

`wave_E = subs(wave_E,lhs(dMaxwell4),rhs(dMaxwell4))`
```wave_E(X, t) =  ```

Using similar steps, you can also find the wave equation for the magnetic field.

`wave_B = curl(Maxwell4,X)`
```wave_B(X, t) =  ```
`wave_B = subs(wave_B,lhs(Maxwell3),rhs(Maxwell3))`
```wave_B(X, t) =  ```
`dMaxwell2 = diff(Maxwell2,t)`
```dMaxwell2(X, t) =  ```
`wave_B = subs(wave_B,lhs(dMaxwell2),rhs(dMaxwell2))`
```wave_B(X, t) =  ```

## Input Arguments

collapse all

Three-dimensional symbolic vector field, specified as a vector of symbolic scalar variables, symbolic function, symbolic matrix variable, or symbolic matrix function. `V` must have a size of `1`-by-`3` or `3`-by-`1`.

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

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

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

Three-dimensional vector with respect to which you find the curl, specified as a vector of symbolic scalar variables, symbolic function, symbolic matrix variable, or symbolic matrix function. `X` must have a size of `1`-by-`3` or `3`-by-`1`.

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

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

## Limitations

• The `curl` function does not support tensor derivatives. If the input `V` is a tensor field or a matrix rather than a vector, then the `curl` function returns an error.

• 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`.

collapse all

### Curl of Symbolic Vector Field

The curl of the symbolic vector field V = (V1, V2, V3) with respect to the vector X = (X1, X2, X3) in Cartesian coordinates is this vector.

`$curl\left(V\right)={\nabla }_{X}×V=\left(\begin{array}{c}\frac{\partial {V}_{3}}{\partial {X}_{2}}-\frac{\partial {V}_{2}}{\partial {X}_{3}}\\ \frac{\partial {V}_{1}}{\partial {X}_{3}}-\frac{\partial {V}_{3}}{\partial {X}_{1}}\\ \frac{\partial {V}_{2}}{\partial {X}_{1}}-\frac{\partial {V}_{1}}{\partial {X}_{2}}\end{array}\right)$`

## Version History

Introduced in R2012a

expand all