# Vector operators in Cartesian coordinates

``continuum_mechanics`` support major vector operators such as:

- gradient of a scalar function;

- divergence of a vector function;

- curl of a vector function;

- gradient of a vector function;

- divergence of a tensor;

- Laplace operator of a scalar function;

- Laplace operator of a vector function; and

- Biharmonic operator of a scalar function.

All these operators are in the module `vector`.


```python
from sympy import *
from continuum_mechanics import vector
```

By default Cartesian coordinates are given by $x$, $y$ and $z$.
If these coordinates are used there is not necessary to specify
them when calling the vector operators


```python
init_printing()
x, y, z = symbols("x y z")
```

Following, we have some examples of vector operators in Cartesian coordinates.

## Gradient of a scalar function

The gradient takes as input a scalar and returns a vector,
represented by a 3 by 1 matrix.


```python
f = 2*x + 3*y**2 - sin(z)
f
```


```python
vector.grad(f)
```

## Divergence of a vector function

The divergence takes as input a vector (represented by a 3 by 1 matrix) and returns a scalar.


```python
vector.div(Matrix([x, y, z]))
```


```python
vector.div(Matrix([
    x**2 + y*z,
    y**2 + x*z,
    z**2 + x*y]))
```

## Divergence of a tensor function

The divergence of a tensor (represented by a 3 by 3 matrix)
returns a vector.


```python
Axx, Axy, Axz = symbols("A_xx A_xy A_xz", cls=Function)
Ayx, Ayy, Ayz = symbols("A_yx A_yy A_yz", cls=Function)
Azx, Azy, Azz = symbols("A_zx A_zy A_zz", cls=Function)
```


```python
tensor = Matrix([
    [Axx(x, y, z), Axy(x, y, z), Axz(x, y, z)],
    [Ayx(x, y, z), Ayy(x, y, z), Ayz(x, y, z)],
    [Azx(x, y, z), Azy(x, y, z), Azz(x, y, z)]])
tensor
```


```python
vector.div_tensor(tensor)
```

## Curl of a vector function

Let us check the identity

$$\nabla \times \nabla f(x, y, z) = \mathbf{0}\, .$$


```python
fun = symbols("fun", cls=Function)
vector.curl(vector.grad(fun(x, y, z)))
```

91913e42612ae2f25b3e794d6e49914a183a241b
ipynb
Jupyter Notebook
docs/cartesian_coordinates.ipynb
nicoguaro/continuum_mechanics
f8149b69b8461784f6ed721294cd1a49ffdfa3d7
MIT
2018-12-09T15:02:51.000Z
2022-02-16T09:28:38.000Z
docs/cartesian_coordinates.ipynb
nicoguaro/continuum_mechanics
f8149b69b8461784f6ed721294cd1a49ffdfa3d7
MIT
2019-05-06T16:31:50.000Z
2022-03-31T21:21:03.000Z
docs/cartesian_coordinates.ipynb
nicoguaro/continuum_mechanics
f8149b69b8461784f6ed721294cd1a49ffdfa3d7
MIT
2020-01-29T10:03:52.000Z
2022-02-25T19:34:37.000Z
Qwen/Qwen-72B
1. YES
2. YES