# Vector Fields

**Example:** Plot of vector field 
$$\vec{F}(x,y) = \mathbf{i}  - \mathbf{j}$$


```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib qt

x,y = np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10))

u = x
v = y

plt.quiver(x,y,u,v)
plt.show()
```

**Example:** Plot of vector field 
$$\vec{F}(x,y) = \frac{x}{\sqrt{x^2 + y^2}} \mathbf{i} + \frac{y}{\sqrt{x^2 + y^2}} \mathbf{j}$$






```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib qt

x,y = np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10))

u = -x/(x**2 + y**2)**(1.5)
v = -y/(x**2 + y**2)**(1.5)

plt.quiver(x,y,u,v)
plt.show()
```

**Example:** Plot of vector field 
$$\vec{F}(x,y) = -\frac{y}{\sqrt{x^2 + y^2}} \mathbf{i} + \frac{x}{\sqrt{x^2 + y^2}} \mathbf{j}$$






```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

x,y = np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10))

u = -y/np.sqrt(x**2 + y**2)
v = x/np.sqrt(x**2 + y**2)

plt.quiver(x,y,u,v)
plt.show()
```


```python
plt.quiverkey?
```

# 3d Vector Field 


```python
%reset -f
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline


fig = plt.figure()
ax = fig.gca(projection='3d')

x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
                      np.arange(-0.8, 1, 0.2),
                      np.arange(-0.8, 1, 0.8))

u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
     np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, color = 'black')

plt.show()
```

# Curl of vector Fields

Import necessary sympy libraries


```python
%reset -f             
from sympy import *    
init_printing()        # for nice math output 
```

Define variables


```python
x,y,z = symbols('x y z')
```

## Create a  Curl Macro

Define a function to calculate curl of vector field $\mathbf{F} = F_1 \mathbf{i} + F_2 \mathbf{j} +  F_3 \mathbf{k
} $

$$
\mathbf{curl} (\mathbf{F}) = \left| 
\begin{array}{ccc}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\
F_1 & F_2 & F_3
\end{array}
\right|
$$




```python
def curl(F):
    c1 = diff(F[2],y) - diff(F[1],z)
    c2 = diff(F[0],z) - diff(F[2],x)
    c3 = diff(F[1],x) - diff(F[0],y)
    return [c1,c2,c3]
    
```

### Example

Evaluate curl of $\mathbf{F} = (2x - y^2)\mathbf{i} +(3z + x^2)  \mathbf{j} + (4y - z^2) \mathbf{k} $



```python
F = [2*x - y**2, 3*z + x**2, 4*y - z**2]
curl(F)
```


```python
F = [2*x + y*z, 2*y+z*x,  2*z+ x*y]
curl(F)
```


```python

```

cd2e631534ac7074a433bc396e7ff2614fa17852
ipynb
Jupyter Notebook
sympy/vectorFields.ipynb
krajit/krajit.github.io
221c8bcdf0612b3ae28c827809aa309ea6a7b0c2
MIT
2018-09-29T07:40:07.000Z
2022-02-28T22:17:04.000Z
sympy/vectorFields.ipynb
krajit/krajit.github.io
221c8bcdf0612b3ae28c827809aa309ea6a7b0c2
MIT
2019-08-26T08:42:47.000Z
2019-08-26T09:48:21.000Z
sympy/vectorFields.ipynb
krajit/krajit.github.io
221c8bcdf0612b3ae28c827809aa309ea6a7b0c2
MIT
2017-09-09T23:32:09.000Z
2020-01-28T21:11:39.000Z
Qwen/Qwen-72B
1. YES
2. YES